andy
andy

Reputation: 8875

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.

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?

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!

Upvotes: 0

Views: 150

Answers (1)

Stefan Steinegger
Stefan Steinegger

Reputation: 64628

It's only possible with detached criteria.

On the other hand, filtering by "count" is very easy using HQL:

from bowl where fruits.size > 1

Criteria API is not as powerful as HQL. Unfortunately, all this linq-style API's are based on criteria.

Upvotes: 1

Related Questions