1 public override System.Linq.Expressions.Expression<Func<I_Position_Access, bool>> GetWhereLambda(I_Position_Access t) 2 { 3 ParameterExpression parameter = Expression.Parameter(typeof(I_Position_Access), "b");//创建参数b 4 System.Linq.Expressions.ConstantExpression constant = Expression.Constant(t.I_Position_AccessID);//创建常数 5 MemberExpression member = Expression.PropertyOrField(parameter, "I_Position_AccessID"); 6 7 System.Linq.Expressions.BinaryExpression bin = 8 Expression.GreaterThan(member, constant);//创建 i > 常数 9 10 if (t.I_Position_AccessID > 0) 11 { 12 constant = Expression.Constant(t.I_Position_AccessID); 13 member = Expression.PropertyOrField(parameter, "I_Position_AccessID"); 14 bin = Expression.Equal(member, constant); 15 } 16 if (t.I_PositionID > 0) 17 { 18 constant = Expression.Constant(Convert.ToInt32(t.I_PositionID), typeof(int?)); 19 member = Expression.PropertyOrField(parameter, "I_PositionID"); 20 System.Linq.Expressions.BinaryExpression where2 = Expression.Equal(member, constant); 21 22 bin = Expression.And(bin, where2); 23 } 24 if (t.I_AccessID > 0) 25 { 26 constant = Expression.Constant(Convert.ToInt32(t.I_AccessID), typeof(int?)); 27 member = Expression.PropertyOrField(parameter, "I_AccessID"); 28 System.Linq.Expressions.BinaryExpression whereI_AccessID = Expression.Equal(member, constant); 29 bin = Expression.And(bin, whereI_AccessID); 30 } 31 if (t.OpenState > 0) 32 { 33 constant = Expression.Constant(Convert.ToInt32(t.OpenState), typeof(int?)); 34 member = Expression.PropertyOrField(parameter, "OpenState"); 35 System.Linq.Expressions.BinaryExpression whereOpenState = Expression.Equal(member, constant); 36 bin = Expression.And(bin, whereOpenState); 37 } 38 return Expression.Lambda<Func<I_Position_Access, bool>>(bin, parameter); 39 //获取Lambda表达式 40 }