Question

J'ai une liste avec les numéros (5,9,3) en elle. Appelons-le MyList

Je voudrais effectuer

var results = from a in myEntities.thing1 where a.ID belongsto MyList select a;

en ce moment je fais

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);
}

Je suis sûr qu'il doit y avoir une meilleure façon, mais je ne peux pas tout à fait envelopper la tête autour.

Était-ce utile?

La solution

var results = from a in myEntities.thing1 where MyList.Contains(a) select a;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top