Mongodb, linq driver. How to construct Contains with variable or statements
Posted
by
Syska
on Stack Overflow
See other posts from Stack Overflow
or by Syska
Published on 2012-06-06T22:07:30Z
Indexed on
2012/06/06
22:40 UTC
Read the original article
Hit count: 147
I'm using the LINQ Driver for C#, works great.
Sorting a lot of properties but heres a problem I can't solve, its probebly simple.
var identifierList = new []{"10", "20", "30"};
var newList = list.Where(x => identifierList.Contains(x.Identifier));
This is NOT supported ...
So I could do something like:
var newList = list.Where(x => x.Identifier == "10" || x.Identifier == "20" || x.Identifier == "30");
But since the list is variable ... how do I construct the above? Or are there even better alternatives?
The list
is of type IQueryable<MyCustomClass>
For information ... this is used as a filter of alot of properties. In SQL I could have a parent -> child relationship. But as I can't as the parent for the main ID I need to take all the ID's out and then construct it like this.
Hopes this makes sense. If needed I will explain more.
© Stack Overflow or respective owner