0

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_IsDummy 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)

Daniel Schilling
  • 4,829
  • 28
  • 60
k.c.
  • 1,755
  • 1
  • 29
  • 53

1 Answers1

1

You have to make a property virtual, even if it not mapped. Otherwise, NHibernate can't properly generate proxy for lazy loading your object.

mathieu
  • 30,974
  • 4
  • 64
  • 90