查找子集合中不包含任何项目的所有项目 [英] Find all items where child collection doesn't contain an item

查看:62
本文介绍了查找子集合中不包含任何项目的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出:

public class Order
{
    public string Name {get;set;}
    public List<LineItem> LineItems {get; set;}
}

public class LineItem
{
   public string Product {get; set;}
   public int Quantity {get; set;}
}

我正试图弄清楚如何构造一个查询,该查询将返回所有没有包含商品名为"Apple"的LineItem的订单

I'm trying to figure out how to construct a query that will return all the Orders that don't have a LineItem with a Product called "Apple"

推荐答案

我已经考虑了一段时间.它出现了几次.问题在于Raven当前不处理!.Any()或.All()查询.

I've been thinking about this for awhile. It's come up a few times. The problem is that Raven doesn't currently handle !.Any() or .All() queries.

这个特殊的例子将问题简化了很多,以至于让我思考了一条不同的道路.我相信有解决方案.它需要针对静态索引的Lucene查询:

This particular example simplified the problem enough that it got me thinking down a different path. I believe there is a solution. It requires a lucene query against a static index:

public class Orders_ByProduct : AbstractIndexCreationTask<Order>
{
  public Orders_ByProduct()
  {
    Map = orders => from order in orders
                    select new
                    {
                        Product = order.LineItems.Select(x => x.Product)
                    };
  }
}

var ordersWithoutApple = session.Advanced
                                .LuceneQuery<Order, Orders_ByProduct>()
                                .Where("*:* AND -Product: Apple")

这篇关于查找子集合中不包含任何项目的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆