Expression inside a lambda gives error

Asked

Viewed 66 times

2

I created a lambda and tried to create an expression or other. With or(||) it didn’t work. Then, instead of || I added Where. Is that right? This way now:

var resultado = db.T_CRM_StatusPDV
                .Where(a => a.DT_TransacaoV < diaAnt)
                .Where(b => b.DT_ControleV < dataControle)
                .Where(c => c.DE_Cnpj == cnpj)
                .Select(i => new { i.DE_Cnpj }).ToList();
  • Better explain the title on the question

  • Ok, if I did so: . Where((a => a.Dt_transacaov < diaAnt)||b => b.Dt_controlev < dataControle). In that case that would not be the expression, but it was just to illustrate. This expression does not work, so I opted for Where. This is for || or for &&

  • It does work! what is Dt_transacaov is a Datetime, and the diaAnt what type is?

  • Datetime also, is a Datetime.Now.Adddays(-1)

  • The chain of Where is equivalent to a chain of conditions And and not OR.

1 answer

4


With || and &&

var resultado = 
  db.T_CRM_StatusPDV
      .Where(a => (a.DT_TransacaoV < diaAnt || a.DT_ControleV < dataControle) && a.DE_Cnpj == cnpj)
      .Select(i => new { i.DE_Cnpj })
      .ToList();

Obs: See where the parentheses go

Browser other questions tagged

You are not signed in. Login or sign up in order to post.