2
I need to pass a list of Expressions
as a parameter and create the Ands in the most dynamic way possible.
Just like that, whenever I add a new Expression
on the list, I’m going to have to change the class that Expression
also.
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();
Explain better what you want. Want to use a
And
orOr
? Not getting it? What’s the problem?– Maniero
I updated the question. I managed to create the condition with an and, but I need to create the condition from a list of Expressions, so that when I build the class that returns the Expressions and add a new Expression, it returns to Expression with all the mounted And
– Alan Oliveira
It may be me, but it seems that in your question you do not want to have a goal, but when you reach the goal, you want to double the goal. (The Portuguese will understand nothing :) )
– Maniero
kkkkk. That’s right, I’m trying to apply an automated pattern to add the ribbons in Where. Then I will have a list of Expressions, then I need to concatenate with and the conditions, so I add a new, return already know concatenate the conditions.
– Alan Oliveira