简体   繁体   English

在nhibernate查询中的子查询中过滤

[英]filter in subquery in nhibernate query

I have two tables in one-to-many relation: 我有两个表一对多的关系:

product  -> orders

In the Products table (parent) I have the maximum number of products that I can sell, and in the child table (orders) I have the number of products sold for each row. 在“ Products表(父级)中,我拥有可以销售的最大产品数量,在子表(订单)中,我具有每行销售的产品数量。 I need to make a list of products that I have available in stock, filtered by 我需要列出库存中可用的产品列表,并按

 orders.count() <= product.NumberOfProductsInStock

How can I accomplish this with a query in nhibernate? 如何在nhibernate中使用查询完成此操作?

You could do: 您可以这样做:

CurrentSession.Linq<Product>()
    .Where(p => p.NumberOfProductsInStock > 0 && (p.Orders.Count() == 0 || p.Orders.Count() <= p.NumberOfProductsInStock))
    .ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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