简体   繁体   English

C#流利的Nhibernate问题

[英]C# fluent nhibernate question

I am trying to globally disable Fluent NHibernate lazy-loading features, but even after: 我试图全局禁用Fluent NHibernate 延迟加载功能,但即使在:

LazyLoad.Never();
DefaultLazy.Never();

NHibernate in my test code keeps telling the following: 我的测试代码中的NHibernate一直告诉我们:

NHibernate.InvalidProxyTypeException:
The following types may not be used as proxies:

XXXX: method YYYY should be 'public/protected virtual'
      or 'protected internal virtual'

I don't want to mark arbitrary methods of my classes as virtual if I've disabled lazy loading. 如果我禁用了延迟加载,我不想将我的类的任意方法标记为虚拟。 Does this have a solution or maybe I'm doing something wrong? 这有解决方案吗,或者我做错了什么?

If you turn Lazy loading off, then Nhibernate will try to retrieve all the associate properties (eg:- Person class has a Car association property) as soon as you fetch person from the database. 如果您关闭了延迟加载,则从数据库中获取人员后,Nhibernate就会尝试检索所有关联属性(例如:-Person类具有Car关联属性)。

To populate the car property Nhibernate creates a proxy of the person class by inheriting person class and overriding the Carpark property. 要填充car属性,Nhibernate通过继承person类并覆盖Carpark属性来创建person类的代理。

If However, your car property is non virtual, Nhibernate will see if Lazy Loading is on and if it could escape loading the property, however that is not the case with your app and hence the exception. 如果然而,你的car属性是非虚拟的,Nhibernate会看到是否启用了Lazy Loading以及它是否可以转义加载属性,但是你的应用程序不是这种情况,因此也是例外。

For some light reading: http://davybrion.com/blog/2009/03/must-everything-be-virtual-with-nhibernate/ 对于一些轻读: http//davybrion.com/blog/2009/03/must-everything-be-virtual-with-nhibernate/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM