i have the following string array
and would like to convert the contents into a linq Where
clause like the following.
I have ...
var words[] = new string [] { "aaa", "bbb", "ccc", "ddd" };
And would like ....
.Where(x => x.Word == "aaa" && x.Word == "bbb" &&
x.Word开发者_开发百科 == "ccc" && x.Word == "ddd")
Cheers :)
Update: Why && and not ||
This is actually for RavenDb and it's smart enough to convert that linq to a Lucene query with AND
's in there...
So i really need it to be &&
Update 2: More clarrification why I would like to use && and not ||
The Linq provider in RavenDB, when told to translate the linq to lucene, does the following..
.Where(x => x.Word == "aaa" && x.Word == "bbb")
get's translated to
Query:aaa AND Query:bbb
so please, i would really appreciate any help and not suggetions to use ||
. This is not linq to objects
or linq to ef
, etc..
.Where(x => words.Contains(x.Word))
UPD: this was perfectly valid for initial revision of the question
If you want to use &&
then you're asking for all the conditions to be satisfied. You could try the All
operator:
.Where(item => words.All(word => word == item));
This seems extremely counterintuitive but is worth a try!
精彩评论