[英]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. 我有以下string array
并想将内容转换为linq Where
子句,如下所示。
var words[] = new string [] { "aaa", "bbb", "ccc", "ddd" };
.Where(x => x.Word == "aaa" && x.Word == "bbb" &&
x.Word == "ccc" && x.Word == "ddd")
Cheers :) 干杯:)
This is actually for RavenDb and it's smart enough to convert that linq to a Lucene query with AND
's in there... 这实际上是针对RavenDb的,它足够聪明,可以将linq转换为其中包含AND
的Lucene查询...
So i really need it to be &&
所以我真的需要它成为&&
The Linq provider in RavenDB, when told to translate the linq to lucene, does the following.. 当被告知将linq转换为lucene时,RavenDB中的Linq提供程序将执行以下操作。
.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.. 这不是linq to objects
linq to ef
也不是linq to ef
,等等。
.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: 您可以尝试使用All
运算符:
.Where(item => words.All(word => word == item));
This seems extremely counterintuitive but is worth a try! 这似乎非常违反直觉,但值得尝试!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.