开发者

Using Fluent NHiberanate how do I turn off the mapping of a non persistent property

开发者 https://www.devze.com 2023-02-25 02:04 出处:网络
All my persistent objects have a property which should not be persisted. At this moment i generate my automapping like this:

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.

0

精彩评论

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