我有一个从 WSDL 生成的类,该类具有一堆公共属性和一个公共事件。我正在用我自己的类扩展这个类并向其添加一些属性。我自己的所有属性都被声明为虚拟的,但基类属性不是虚拟的。
我正在使用 Fluent NHibernate 的 ClassMap 仅映射扩展类中的属性。如何防止 (Fluent)NHibernate 尝试保留所有基类的公共成员?
目前,我在创建 ISessionFactory 时遇到以下异常:
NHibernate.InvalidProxyTypeException:以下类型不能用作代理:
类型:方法 get_>应为“公共/受保护的虚拟”或“受保护的内部虚拟”
类型:方法set_>应为“公共/受保护的虚拟”或“受保护的内部虚拟”
...
类型:方法add_>应为“公共/受保护的虚拟”或“受保护的内部虚拟”
类型:方法remove_>应为“公共/受保护的虚拟”或“受保护的内部虚拟”
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_<BaseClassEvent
> should be 'public/protected virtual' or 'protected internal virtual'
Type: method remove_<BaseClassEvent
> should be 'public/protected virtual' or 'protected internal virtual'
发布评论
评论(1)
Fluent NHibernate 并不试图保留所有公共成员。这是 NHibernate 代理机制,要求所有成员都是虚拟的;它们可能会也可能不会用于持久性,但无论如何它们都是需要的。
您需要禁用实体的延迟加载和代理,或者(最好!)在 WS 中公开 DTO,而不是直接暴露实体。
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.