Implementing 'belongs' with LINQ queries
I have a List with the numbers (5,9,3) in it. Let's call it MyList
I would like to perform
var results = from a in myEntities.thing1 where a.ID belongsto MyList select a;
right now I do
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);
}
I'm sure there must be a better way, but I can't quite wrap my head around it.
var results = from a in myEntities.thing1 where MyList.Contains(a) select a;
精彩评论