开发者

Implementing 'belongs' with LINQ queries

开发者 https://www.devze.com 2022-12-11 13:59 出处:网络
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;

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消