I'm trying to creating a dynamic base mapping with fluent nhibernate.
What I'm doing is checking in by a BaseMap< T > : ClassMap< T > if for example: (typeof(ICategorizedEntity).IsAssignableFrom(typeof(T)))
If so, I wanna map a property named "Category" which belongs to ICategorizedEntity's interface, but the Map(Func) function only accepts T's properties, so I tried guessing a little with linq and came up with this:
Expression<Func<ICategorizedEntity, object>> exp = x => x.Category;
var parameter = Expression.Parameter(typeof (T));
var lmd = Expression.Lambda<Func<T, object>>(exp, parameter);
Map(lmd);
Which doesn't work, because deep inside the 'Map' function it checks the following:
MemberExpression memberExpression = (MemberExpression) null;
if (expression.NodeType == ExpressionType.Convert)
memberExpression = ((UnaryExpression) expression).Operand as MemberExpression;
else if (expression.NodeType == ExpressionType.MemberAccess)
memberExpression = expression as MemberExpression;
if (enforceCheck && memberExpression == null)
throw new ArgumentException("Not a member access", "expression");
And I get the "Not a member access\r\nParameter name: expression".
How can I create and cast a MemberExpression or anything similar which will work?