Implementar 'pertence' com consultas LINQ
-
20-09-2019 - |
Pergunta
Eu tenho uma lista com os números (5,9,3). Vamos chamá -lo de mylist
Eu gostaria de realizar
var results = from a in myEntities.thing1 where a.ID belongsto MyList select a;
agora eu faço
List<T> t = new List<T>(); //I actually define T to a strong type
foreach (int i in MyList)
{
t.add(from a in myEntities.thing1 where a.ID==i select a);
}
Tenho certeza de que deve haver uma maneira melhor, mas não consigo entender.
Solução
var results = from a in myEntities.thing1 where MyList.Contains(a) select a;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow