有没有办法将表达式列表合并成一个? 我有一个 List<Expression<Child, bool>> expList
,想要将它们合并成一个(AndAlso) 并得到
Expression<Child, bool> combined = Combine(expList);
组合表达式的预期用途如下:
//type of linqFilter is IQueryable<Parent>
linqFilter = linqFilter.SelectMany(p => p.Child).
Where(combined).Select(t=> t.Parent);
我正在尝试类似于这样的东西:
var result = expList.Cast<Expression>().
Aggregate((p1, p2) => Expression.AndAlso(p1, p2));
但是出现异常
{"The binary operator AndAlso is not defined for the types 'System.Func`2[Child,System.Boolean]' and 'System.Func`2[Child,System.Boolean]'."}