确实尚不支持包含(也许应该支持,但这完全是另一回事 - 我们仅在需要时才真正添加对各种运算符的支持)
至于针对 Any 的多个查询,我假设您正在尝试处理动态数据并且您想要实现类似
"X OR Y OR Z"
这是一个棘手的问题,默认情况下 LINQ 提供程序将使用 AND 聚合这些多个 WHERE 子句,因此您的示例看起来像
"X AND Y AND Z"
显然永远不会是这样。
您最好的选择是下拉到 Lucene 查询(至少现在是这样)并执行以下操作:
var results = s.Advanced.LuceneQuery<Item>()
.Where(string.Format("Tags,:({0})", string.Join(" OR ", tags)));
有道理?
上面的查询看起来像
"Tags,:(X OR Y OR Z)"
注意:“标签”通知 RavenDB 标签是一个数组
好的,[编辑]!
获得你真正想要的最简单的方法是按照这些思路做一些事情
new IndexDefinition<Item, Item>()
{
Map = docs => from doc in docs
select new
{
Tags = doc.Tags
},
Indexes = {{ x => x.Tags, FieldIndexing.Analyzed }}
}.ToIndexDefinition(store.Conventions));
然后查询你的ands,你可以这样做:
var results = s.Advanced.LuceneQuery<Item, WhateverYouCalledThatIndex>()
.Where(string.Format("Tags:({0})", string.Join(" AND ", tags)));
现在,需要注意的事情
Tags = doc.Tags
会将整个数组序列化为一个巨大的 blob,因为它只是适用于本示例的字符串。
I am looking at better ways of expressing this, it is unlikely that we'll come up with a LINQ-ish way of doing this, as it doesn't really map across very well - but it is an answer that will work :)
I think I'd quite like to be able to at least do
Map = docs => from doc in docs
select new
{
Tags = String.Join(" ", doc.Tags)
},
(This won't work so don't try it), but it is a bit more explicit about what you want to achieve.