开发者

C# fluent nhibernate question

I a开发者_StackOverflow社区m trying to globally disable Fluent NHibernate lazy-loading features, but even after:

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

NHibernate in my test code keeps telling the following:

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.

To populate the car property Nhibernate creates a proxy of the person class by inheriting person class and overriding the Carpark property.

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.

For some light reading: http://davybrion.com/blog/2009/03/must-everything-be-virtual-with-nhibernate/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜