All my persistent objects have a property which should not be persisted.
At this moment i generate my automapping like this:
var autoMap =
AutoMap.AssemblyOf<BaseEntity>()
.Where(type => type.Namespace != null && type.Namespace.Contains("Models"))
.Conventions.AddFromAssemblyOf<IEntity>()
.OverrideAll(map => map.IgnoreProperty("IsDummy"));
However the following error is returned:
System.TypeInitializationException: System.TypeInitializationException: The type initializer for 'Core.Context' threw an exception. ---> NHibernate.InvalidProxyTypeException: The following types may not be used as proxies: Core.Models.MyEntity: method get_IsD开发者_JAVA技巧ummy should be 'public/protected virtual' or 'protected internal virtual'
This leads me to believe that the override did not work. (Core.Context is the class triggering the mapping process)
You have to make a property virtual, even if it not mapped. Otherwise, NHibernate can't properly generate proxy for lazy loading your object.
精彩评论