Is it possible to have an IN clause with lambda expression? Type:
context.tabela.Where(a => a.meu_campo_id_tipo_inteiro....)
let's say an in like this: (2,3,4,5) How do I put on the dots?
Is it possible to have an IN clause with lambda expression? Type:
context.tabela.Where(a => a.meu_campo_id_tipo_inteiro....)
let's say an in like this: (2,3,4,5) How do I put on the dots?
More or less. The way to do it is like this:
var inteirosPraAchar = new List<int> {2, 3, 4, 5};
context.tabela.Where(a => inteirosPraAchar.Contains(a.meu_campo_id_tipo_inteiro));
An alternative to the method in the @Cypsy answer:
List<int> inteirosParaAchar = new List<int> { 1, 2, 3, 4 };
context.Where(i => inteirosParaAchar.Any(i1 => i1 == i));
For the reasons stated in this response (for flexibility), using Any makes comparison more flexible and can be extended to include more comparison elements.
Excerpt from answer:
Finally, .Any () due to the delegate, is more flexible than the .Contains () that only accepts an object.