سؤال

لدي قائمة مع الأرقام (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;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top