Domanda

Ho una lista con i numeri (5,9,3) in esso. Chiamiamolo MyList

Vorrei svolgere

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

in questo momento faccio

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

Sono sicuro che ci deve essere un modo migliore, ma non riesco a avvolgere la mia testa intorno ad esso.

È stato utile?

Soluzione

var results = from a in myEntities.thing1 where MyList.Contains(a) select a;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top