Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用LINQ查询实现“归属”_C#_Linq_Belongs To - Fatal编程技术网

C# 使用LINQ查询实现“归属”

C# 使用LINQ查询实现“归属”,c#,linq,belongs-to,C#,Linq,Belongs To,我有一张清单,上面有数字5,9,3。让我们称之为MyList 我想表演 var results = from a in myEntities.thing1 where a.ID belongsto MyList select a; 现在我知道了 List<T> t = new List<T>(); //I actually define T to a strong type foreach (int i in MyList) { t.add(from a in myE

我有一张清单,上面有数字5,9,3。让我们称之为MyList

我想表演

var results = from a in myEntities.thing1 where a.ID belongsto MyList select a;
现在我知道了

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

我确信一定有更好的方法,但我不能完全理解它。

LINQ2SQL有一个窍门,MyList必须是对列表或数组的强类型引用。如果您传递一个IList,linq2sql将无法编译。这是linq2sql的一个技巧,MyList必须是对列表或数组的强类型引用。如果传递ILST,linq2sql将无法编译
var results = from a in myEntities.thing1 where MyList.Contains(a) select a;