Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate QueryOver Having clause

I want to write such a query with QueryOver so that the result SQL will be similar to the following:

Select Bar, count(*) from Foo group by Bar having count(*) > 1

How can I do it ?

like image 739
emperon Avatar asked Jun 15 '11 13:06

emperon


1 Answers

I think you would just use the Where method

Session.QueryOver<Foo>()
    .Select(Projections.GroupProperty(Projections.Property<Foo>(foo => foo.Bar)),
            Projections.Count<Foo>(f => f.Id))
    .Where(Restrictions.Gt(Projections.Count<Foo>(f => f.Id), 1));
like image 50
Vadim Avatar answered Oct 19 '22 01:10

Vadim