我有两个课程:
class Customer
{
public string Fullname { get; set; }
public string Lastname { get; set; }
public int Age { get; set; }
}
和
class CustomerDTO
{
public string Fullname { get; set; }
public string Lastname { get; set; }
public int Age { get; set; }
}
现在我有一个表达式Expression<Func<Customer, bool>> expression
在层之间传递,我可以将它转换为Expression<Func<CustomerDTO, bool>> expression
以便能够使用它,因为它会给编译时错误!
提前致谢
答案 0 :(得分:0)
没关系,我做到了
Expression<Func<Customer, bool>> expression = v => v.Fullname == "Johm";
var par = Expression.Parameter(typeof(CustomerDTO));
Expression<Func<CustomerDTO, bool>> ex = (Expression<Func<CustomerDTO, bool>>)Expression.Lambda(expression.Body, par);