我想为看起来像这样的查询表达式创建一个表达式树:employee => employee.Salary.StartsWith("28")
这样 sql 就可以显示为: where (employee.salary like '28%')
问题是员工对象的属性 Salary 是小数,而 StartsWith 不是小数的属性。我怎样才能做到这一点。
我错误的表达式树语法如下:
var searchTextExp = Expression.Constant("28");
var parameterExp = Expression.Parameter(typeof(EmployeeEntity), "employee");
var propertyExp = Expression.Property(parameterExp, "Salary");
var startsWithExp = Expression.Call(propertyExp, "StartsWith", null,
searchTextExp);
Expression<Func<EmployeeEntity, bool>> searchExpr =
Expression.Lambda<Func<EmployeeEntity, bool>>
(startsWithExp, new ParameterExpression[] { parameterExp });