views:

31

answers:

1

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!

+1  A: 

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.

Stefan Steinegger
+1 thanks dude. yeah, the more I use the criteria api, the more sucky it is! I'm surprised the api doesn't just translate into hql first? if it did then the api should be able to handle "fuits.size" in the property parameter... I'll try this out, cheers
andy
unfortunately, criteria does not translate to hql.
Stefan Steinegger
cool, cheers dude. It is strange that it doesn't isn't it..? anyways, cheers
andy