views:

102

answers:

1

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'

+2  A: 

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.

James Gregory
I'm not the author of the WS, so I can't change anything from that end. Looks like I'll have to disable lazy-loading. Thanks.
alimbada
Is it correct to disable lazy-loading just for that entity by calling `Not.LazyLoad()` in the constructor of the ClassMap? Or is there a better way to do this? There seems to be a few ways to do it here: http://stackoverflow.com/questions/1412002/fluent-nhibernate-r1-0-fluent-mapping-disable-lazy-load
alimbada
`Not.LazyLoad()` in the `ClassMap` is the easiest way to go if it's only particular entities that need it doing; if it's everything, you should look into a convention (one of the answers in that question you linked to uses the `DefaultLazy` convention).
James Gregory