日期:2014-05-17 浏览次数:20819 次
public static Expression<Func<TEntity, bool>> ConvertExpression(Expression<Func<TEntity, int>> IdExp, int value)
{
ParameterExpression para = IdExp.Parameters[0];
MemberExpression member = (MemberExpression)IdExp.Body;
ConstantExpression con = Expression.Constant(value);
var left = Expression.Property(para, para.Type.GetProperty(member.Member.Name));
var exp = Expression.Equal(left, con);
return Expression.Lambda<Func<TEntity, bool>>(exp, para);
}