tags:

views:

60

answers:

3

I'm trying to get all the assets where Class property equals to one of the values in selectedIClassesList;

Something like this:

from x in Assets where selectedIClassesList.Contains(x.Class) select x
+2  A: 
Assets.Where(x=>selectedIClassesList.Contains(x.Class));
Ngu Soon Hui
+3  A: 

You could do a join...

var query = from a in Assets
            join s in selectedClassesList on a.Class equals s
            select a;
rchern
+1 Beat me to it!
masenkablast
A: 

If I understand right, your problem is that IClassesList doesn't have a contains method? If IClassesList is an IEnumerable of the same type of object as x.Class, this should work.

from x in Assets where selectedIClassesList.Any(s => s == x.Class) select x

For better performance, you would do well to create a dictionary, though.

var selectedClassesDict = selectedIClassesList.ToDictionary(s => s);
var selectedAssets = from a in Assets 
                     where selectedClassesDict.ContainsKey(a.Class)
                     select a;
StriplingWarrior
Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
Ike