views:

39

answers:

1

I have a List with the numbers (5,9,3) in it. Let's call it MyList

I would like to perform

var results = from a in myEntities.thing1 where a.ID belongsto MyList select a;

right now I do

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

I'm sure there must be a better way, but I can't quite wrap my head around it.

+6  A: 
var results = from a in myEntities.thing1 where MyList.Contains(a) select a;
Corey Sunwold
I am dumb.............
Matt
There is a trick there for LINQ2SQL, the "MyList" must be strong type reference to a "List<>" or an "array".If you pass a "IList" the linq2sql will failed to compile
Dennis Cheung