开发者

Help me with Linq query please

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

Something lik开发者_如何学Ce this:

from x in Assets where selectedIClassesList.Contains(x.Class) select x


You could do a join...

var query = from a in Assets
            join s in selectedClassesList on a.Class equals s
            select a;


Assets.Where(x=>selectedIClassesList.Contains(x.Class));


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜