Implementación de 'pertenece' con consultas LINQ
-
20-09-2019 - |
Pregunta
Tengo una Lista con los números (5,9,3).Llamémoslo Mi Lista
me gustaria actuar
var results = from a in myEntities.thing1 where a.ID belongsto MyList select a;
ahora mismo lo hago
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);
}
Estoy seguro de que debe haber una manera mejor, pero no puedo entenderlo del todo.
Solución
var results = from a in myEntities.thing1 where MyList.Contains(a) select a;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow