lambada

时间:2022-02-06 15:08:38

一、动态创建

ParameterExpression parameter = Expression.Parameter(typeof(User), "u");  //创建委托

MemberExpression member = Expression.PropertyOrField(parameter, "F_FullName");  //创建查询字段

ConstantExpression constant = Expression.Constant("张苏纳");  //变量赋值

var expression= Expression.Equal(member, constant);  //创建匹配条件

var lambda = Expression.Lambda<Func<User, bool>>(expression, parameter);  

var list = dbcontext.Set<User>().Where(lambda);//创建完整查询条件