简体   繁体   English

如何在不使用分离条件的情况下按nhibernate中的属性计数进行查询?

[英]How do I query by the count of a property in nhibernate without using a detached criteria?

hey guys, I'm using NHibernate version 2.1.2.4000. 大家好,我使用的是NHibernate 2.1.2.4000版。

The Entity 实体

class bowl
{
    int id { get; set; }
    List<fruit> fruits { get; set; }
}

The Desired (pseudo) Query 所需(伪)查询

var bowls = repository.where(b => b.fruits.count > 1);

The Question 问题

How do I do the above query using the NHibernate criteria API? 如何使用NHibernate条件API进行上述查询?

Ideally I'd like to be able to do something like this (no subqueries, no detached criterias): 理想情况下,我希望能够执行以下操作(没有子查询,没有分离的条件):

var bowls = repository.where(Restrictions.Gt("fruits.count", 1));

Is the above possible somehow? 以上可能以某种方式吗?

cheers! 干杯!

It's only possible with detached criteria. 只有分离条件才有可能。

On the other hand, filtering by "count" is very easy using HQL: 另一方面,使用HQL非常容易按“计数”进行过滤:

from bowl where fruits.size > 1

Criteria API is not as powerful as HQL. Criteria API不如HQL强大。 Unfortunately, all this linq-style API's are based on criteria. 不幸的是,所有这些linq风格的API都是基于条件的。

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

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