我正在使用NHibernate与传统rdbms规则引擎。我正在使用GenericDialect但生成的一些sql不起作用。如果我需要编写自定义方言这个规则引擎怎么启动?如何编写自定义nHibernate方言?
0
A
回答
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();
相关问题
- 1. NHibernate自定义方言
- 2. 如何编写自定义断言Python
- 3. 如何编写自定义断言?
- 4. 如何编写自定义XCTest断言的自动化测试?
- 5. 如何编写自定义的NHibernate HQL发电机
- 6. 如何编写自定义JUnit断言的测试?
- 7. 如何编写自定义PHPUnit断言,其行为如同内置断言?
- 8. Boost.Asio:如何编写自定义AsyncReadStream?
- 9. 如何编写自定义例外?
- 10. 如何编写自定义JOptionPane按钮?
- 11. 如何编写自定义ExpandableListAdapter
- 12. 如何编写自定义UITextField类
- 13. jQuery - 如何编写自定义队列?
- 14. 如何编写自定义printf?
- 15. 如何编写自定义函数CNTK
- 16. 如何编写自定义Linq组合
- 17. 如何编写checkstyle自定义检查?
- 18. 如何编写自定义dbcontext
- 19. 用def编写自定义方法
- 20. 如何编写自定义流式自定义操作器
- 21. 为自定义语言编写文本编辑器
- 22. NHibernate的:自定义方言 - 如何在一个单独的程序
- 23. 如何编写一个包含自定义Shape类的方法
- 24. 如何编写自定义视图的设置方法
- 25. 如何为array.prototype.find作为自定义方法编写polyfill?
- 26. 如何在RoR中编写自定义方法?
- 27. 如何在Python中编写自定义的`.assertFoo()`方法?
- 28. 如何为字体和方向编写自定义IBInspectable?
- 29. 如何编写自定义servlet上下文初始化方法
- 30. 如何在java中编写自定义函数/方法? (RFT)