简体   繁体   中英

Can I can convert this C# code into some Linq code?

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 :这对于问题的初始修订完全有效

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM