我有以下代码。我尝试在查询的Where子句的表达式中传递对IsActive的调用,但它不执行
protected Expression<Func<vAccount, bool>> ActiveAccountPredicate => a =>
(
IsActive(a)
)
&& (!a.Foreign || IsShowForeign)
&& (a.RegistrationTypeId != RegistrationType.NotRegistered || IsShowNotRegistered);
public static bool IsActive(vAccount a)
{
return (a.DepartedDate == null || a.DepartedDate >= DateTime.Now)
&& (a.RegistrationTypeId != RegistrationType.NotRegistered || a.SupoDepartedDate == null || a.SupoDepartedDate >= DateTime.Now)
&& (a.RegistrationTypeId != RegistrationType.NotRegistered || a.RegistrationExpiredDate == null || a.RegistrationExpiredDate >= DateTime.Now);
}
有办法做到这一点吗?
您还需要将
IsActive
写为 Expression
。
public static Expression<Func<vAccount, bool>> IsActive => a =>
{
return (a.DepartedDate == null || a.DepartedDate >= DateTime.Now)
&& (a.RegistrationTypeId != RegistrationType.NotRegistered || a.SupoDepartedDate == null || a.SupoDepartedDate >= DateTime.Now)
&& (a.RegistrationTypeId != RegistrationType.NotRegistered || a.RegistrationExpiredDate == null || a.RegistrationExpiredDate >= DateTime.Now);
};