I need to pass a list of Expressions
as a parameter and create the 'Ands' as dynamically as possible.
So, whenever I add a new Expression
to the list, I will have to change the class that mounts Expression
as well.
ParameterExpression c = Expression.Parameter(typeof(Boleto), "Boleto");
var temNegociacao = Expression.IsFalse(Expression.Property(c, "Negociacao"));
var status = Expression.IsTrue(Expression.Property(c, "Status"));
var bolsa = Expression.LessThan(Expression.Property(c, "Bolsa"), Expression.Constant(100.0));
var aberto = Expression.IsTrue(Expression.Property(c, "Aberto"));
var periodoLetivo = Expression.IsTrue(Expression.Property(c, "Periodo"));
Expression<Func<Billet, bool>> condition =
Expression.Lambda<Func<Billet, bool>>(
Expression.And(
Expression.And(temNegociacao,
Expression.And(status,
Expression.And(bolsa,
Expression.And(aberto, periodoLetivo)))), c));
return _dbSet.Where(condition).ToList();