2010-02-27 102 views

回答

3

我會從抓取nhibernate源碼開始,2.1.x分支是here。現有的Dialect都在src/NHibernate/Dialect下。

複製一個並開始黑客攻擊。基類Dialect有許多擴展點。

7

這是一個例子方言:


using System; 
using System.Collections.Generic; 
using System.Web; 

/// 
/// This class ensures that the tables created in our db are handling unicode 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 resources 
return cfg.BuildSessionFactory(); 
相關問題