Predicate with a list of 2 values matching pairs

Asked

Viewed 23 times

0

Hello, everyone.

I have an SQL with filter that the user has the possibility to inform several "cost centers" and "cost sub-centers" combined. That is, in practice, it would be a list with 2 values (possibly 1 only, if only the "Cost Center" is informed) The main thing here is that the predicate would have to be matched pairs. That is, I want to take the records when cost center and cost sub-center is respectively "X and Y" or "G and H" or " T and E" or "T and nothing".

Example:

Select Numero, Valor, idCentroCusto, idCodSubCentroCusto
From Lancamentos
where (idCentroCusto = 10 and idSubCentroCusto = 2) 
      or (idCentroCusto = 11 and idSubCentroCusto = 4)
      or (idCentroCusto = 8) 

Easily done in SQL.

However, how could you implement this logic in LINQ?

If you were to filter only a list of "cost centers" for example, it would be simple, with a Contains.

This predicate is optional, by default in the system we use Predicatebuilder for these cases.

No answers

Browser other questions tagged

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