تنفيذ "ينتمي" مع استفسارات LINQ
-
20-09-2019 - |
سؤال
لدي قائمة مع الأرقام (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);
}
أنا متأكد من أنه يجب أن يكون هناك طريقة أفضل ، لكن لا يمكنني لف رأسي حوله.
المحلول
var results = from a in myEntities.thing1 where MyList.Contains(a) select a;
لا تنتمي إلى StackOverflow