How to combine (AND) two LINQ expressions in one
02.03.2009 Понедельник 12:17
private static Expression<Func<object, bool>> AndExpressions(
Expression<Func<object, bool>> expression1,
Expression<Func<object, bool>> expression2)
{
if (expression1 == null)
{
return expression2;
}
else if (expression2 == null)
{
return expression1;
}
else
{
var invokedExpr = Expression.Invoke(expression2, expression1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<object, bool>>(Expression.AndAlso(expression1.Body, invokedExpr), expression1.Parameters);
}
}