栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何编写自定义nHibernate方言?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何编写自定义nHibernate方言?

这是一个方言示例:

using System;using System.Collections.Generic;using System.Web;/// /// This class ensures that the tables created in our db are handling unipre properly./// public class NHibernateMySQL5InnoDBDialect : NHibernate.Dialect.MySQL5Dialect{    public override String TableTypeString { get { return " ENGINE=InnoDB DEFAULT CHARSET=utf8"; } }}

它所在的程序集引用了NHibernate.dll

hibernate.cfg.dll(请注意,我这里没有设置’connection.connection_string’属性,这是我的特定设置,通常您在这里会有连接字符串):

<?xml version="1.0" encoding="utf-8"?><!-- This is the ByteFX.Data.dll provider for MySql --><hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >  <session-factory name="NHibernate.Test">    <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>    <property name="dialect">NHibernateMySQL5InnoDBDialect, Assembly1</property>    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>  </session-factory></hibernate-configuration>

在某些设置中,方言行是

<property name="dialect">Assembly1.NHibernateMySQL5InnoDBDialect, Assembly1</property>

和创建ISessionFactory的代码:

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();cfg.Configure();cfg.Properties["connection.connection_string"] = ConnectionStringForDatabase();cfg.AddDirectory(PathToMappingsIfYouUseNonStandardDirectory);//not needed if using embedded resourcesreturn cfg.BuildSessionFactory();


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/420154.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号