开发者

Prevent mapping all public members of a class in Fluent NHibernate

开发者 https://www.devze.com 2022-12-29 03:46 出处:网络
I have a class generated from a WSDL that has a bunch of public properties and a public event. I\'m extending this class with my own and adding some properties to it. All of my own properties are decl

I have a class generated from a WSDL that has a bunch of public properties and a public event. I'm extending this class with my own and adding some properties to it. All of my own properties are declared virtual, but the base class properties are not virtual.

I'm using Fluent NHibernate's ClassMap to map only the properties from my extended class. How do I prevent (Fluent)NHibernate from trying to persist all the base class's public members?

At the moment, I get the following exception when creating the ISessionFactory:

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

Type: method get_<BaseClassProperty> should be 'public/protected virtual' or 'protected internal virtual'

Type: method set_<BaseClassProperty> should be 'public/protected virtual' or 'protected internal virtual'

...

Type: method add_<BaseClassEven开发者_高级运维t> should be 'public/protected virtual' or 'protected internal virtual'

Type: method remove_<BaseClassEvent> should be 'public/protected virtual' or 'protected internal virtual'


Fluent NHibernate is not trying to persist all your public members. It's the NHibernate proxying mechanism that requires all members to be virtual; they may or may not be used for persistence, but they're needed anyway.

You either need to disable lazy-loading and proxying for the entity, or (preferably!) expose a DTO in your WS rather than the entity directly.

0

精彩评论

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

关注公众号