Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore mapping of property using mapping by code "Conventions"

Is there any way to avoid a property from being mapped with NHibernate 3.2 using mapping by code conventions? By default, all properties are mapped.

like image 525
Newbie Avatar asked Oct 20 '11 01:10

Newbie


1 Answers

2) As alternative to copy&paste of default implementation of IsPersistentProperty it can be reused via reflection:

var mapper = new ConventionModelMapper();
var field = mapper.ModelInspector.GetType()
    .GetField( "isPersistentProperty", BindingFlags.NonPublic | BindingFlags.Instance );

var ispp = (Func<MemberInfo, bool, bool>)field.GetValue( mapper.ModelInspector );
mapper.IsPersistentProperty( ( mi, b ) => ispp( mi, b ) 
   && ( /*any conditions here*/ mi.Name != "SomeFiledName" ) );

Conditions can be moved to separate method or class. An stronly-typed wrapper based on expressions can be done above it.

like image 193
Vasiliy Shiryaev Avatar answered Nov 15 '22 03:11

Vasiliy Shiryaev