,你可以做到这一点为您的查询创建索引
public class GetOrdersByProductIndex: AbstractIndexCreationTask<Order,GetOrdersByProductIndex.Result>
{
public class Result
{
public string Product {get; set;}
}
public GetOrdersByProductIndex()
{
Map = orders => from order in orders
select new
{
Product = order.LineItems.Select(x => x.Product)
};
}
}
现在你可以使用这个指标,让您的订单。您的查询应该是这样的
using(IDocumentSession session = docStore.OpenSession())
{
var orders = session.Query<GetOrdersByProductIndex.Result,GetOrdersByProductIndex>
.Where(x=>x.Product != "Apple")
.As<Order>()
.ToList()
}
请注意,默认情况下它只会返回128条记录(因为由ravendb设置的限制),如果你的查询结果有超过128分的记录,你应该使用Take(recordsNeeded)
函数取数据。
又见它使用相同的指数形式wizzardz的回答,但他想通了如何表达在简单的linq中查询。 –
当人们想要在两个集合之间执行'.Except',或者'.Any &&!.Any'时,这也很有用。我想找到一个用户是一部分但不活跃的组,并且** Linq **我是:'.Where(g => g.AllUserIdsInGroup.Any(id => userId == id)&&! g.ActiveUserIdsInGroup.Any(id => userId == id))'因为!.Any而失败,但是这个** Lucene查询**工作:''AllUserIdsInGroup:234 AND -ActiveUserIdsInGroup:234“' –