C# 使用LINQ查询实现“归属”
我有一张清单,上面有数字5,9,3。让我们称之为MyList 我想表演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
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;