我有以下功能
public virtual ICollection<T> initData<T>(System.Data.Entity.DbSet<T> set, System.Linq.Expressions.Expression<Func<T, bool>> filter) where T : CModel<T>
{
var x = (from dc in set select dc);
if (!this.db.valid)
{
System.Linq.Expressions.Expression<Func<T, bool>> active = a => a.active;
filter = (Expression<Func<T, bool>>)Expression.Lambda(Expression.AndAlso(filter, active));
x.Where(filter);
}
else
{
x.Where(filter);
}
return (ICollection<T>)x.ToList();
}
每当我尝试将 2 个谓词与AndAlso
i 结合时都会引发异常:
The binary operator AndAlso is not defined for the types 'System.Func`2[namespace.Models.MyClass,System.Boolean]' and 'System.Func`2[namespace.Models.MyClass,System.Boolean]'.
我怎样才能结合这两个条件?