【发布时间】:2011-02-17 01:36:41
【问题描述】:
有什么方法可以将表达式列表合并为一个吗?我有List<Expression<Child, bool>> expList 并试图合并为一个(AndAlso)并得到 p>
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]'."}
【问题讨论】:
标签: linq-to-sql lambda