表达式目录树拼接两个表达式
public static Expression<Func<T, bool>> CreateWhere<T>(string columnName, Type columnType, object value,Expression<Func<T, bool>> expression=null) { if (typeof(T).GetProperties().Any(p=>p.Name==columnName)) { var parameter = Expression.Parameter(typeof(T), "w"); var lambdaBody = Expression.Equal( Expression.PropertyOrField(parameter, columnName), Expression.Constant(value, columnType) ); if (expression != null) { var data = Expression.AndAlso(lambdaBody, expression.Body); return Expression.Lambda<Func<T, bool>>(data, parameter); } return Expression.Lambda<Func<T, bool>>(lambdaBody, parameter); } return null; }