如何将 NHibernate 配置类与 Fluent NHibernate 一起使用
即使在部署代码后我也希望保持灵活性,因此我喜欢使用 hibernate.cfg.xml 文件来配置 NHibernate。现在,我计划使用 Fluent NHibernate 来完成我所有的课程 =>表映射。有没有办法使用旧的 NHibernate 配置类来配置 Fluent NHibernate?
I want to be flexible even after deploying my code so I like to use the hibernate.cfg.xml file for configuring NHibernate. Now, I am planning to use Fluent NHibernate to do all my Class => Table mapping. Is there a way I could use the old NHibernate Configuration class to configure Fluent NHibernate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,如果您使用 Fluent 配置 API,则
Configure
方法具有一个重载,它采用现有的 NHibernateConfiguration
实例,该实例可以从 hibernate.cfg.xml 构建。Yes, if you're using the fluent configuration API the
Configure
method has an overload that takes an existing NHibernateConfiguration
instance, which can be built from your hibernate.cfg.xml.好吧,这显然是我的错。我尝试将 NHibernate Configurtion 对象传递到 Fluently.Configure() 方法中,但我的代码抛出了各种错误。问题出在 NHibernate“Fluent-NHibernate”用户的版本上。我不知道代理工厂类属性现在是强制性的。因此,我的 hibernate.cfg.xml 文件缺少该属性。这很奇怪,Fluent NHibernate 没有给我任何关于这一点的线索。当我尝试使用普通的 NHibernate 时,我发现了这个问题。以下是我的 hibernate.cfg.xml 文件的不同版本。希望它对未来的开发者有所帮助。
第一版
第二版
Alright, So this was obviously my fault. I tried passing the NHibernate Configurtion object into the Fluently.Configure() method, but my code was throwing up all kinds of errors. The problem was with the version of NHibernate 'Fluent-NHibernate' users. I didn't know that the proxy factory class attribute was now mandatory. So, my hibernate.cfg.xml file was missing that attribute. It's wierd, Fluent NHibernate didn't give me any clue about that. It's when I tried using plain NHibernate that I found this problem. Below are the different version of my hibernate.cfg.xml files. Hope it helps future devs.
First Version
Second Version