我正在为nHibernate动态构建linq查询。如何将LambdaExpression转换为键入的表达式<Func<T, T>>
由于依赖关系,我想在以后的时间输入/检索类型化表达式,但到目前为止我一直没有成功。
这不是工作(中投应该在别处发生):
var funcType = typeof (Func<,>).MakeGenericType(entityType, typeof (bool));
var typedExpression = (Func<T, bool>)Expression.Lambda(funcType, itemPredicate, parameter); //Fails
这是工作:
var typedExpression = Expression.Lambda<Func<T, bool>>(itemPredicate, parameter);
是否有可能得到“封装”从LambdaExpression输入表达式?
也许你正在寻找typedExpression.Compile() – jure 2013-04-25 11:07:04
我需要使用表达式作为一个IQueryable与我的ORM映射器,因此它不能被编译。 – Larantz 2013-04-26 07:52:53