使用LINQ查询实现"属于"

Mat*_*att 0 c# linq belongs-to

我有一个包含数字(5,9,3)的列表.我们称之为MyList

我想表演

var results = from a in myEntities.thing1 where a.ID belongsto MyList select a;
Run Code Online (Sandbox Code Playgroud)

现在我做

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);
}
Run Code Online (Sandbox Code Playgroud)

我敢肯定必须有一个更好的方法,但我不能完全围绕它.

Cor*_*old 6

var results = from a in myEntities.thing1 where MyList.Contains(a) select a;
Run Code Online (Sandbox Code Playgroud)