views:

337

answers:

1

I have a Person entity belongs to a person has a Country, I want to select all the distinct countries that have people in them. Easy in HQL

select distinct p.Country from Person p

How can I do this using a Criteria Query?

+2  A: 
criteria.SetProjection(Projections.Distinct(Projections.Property("Country")));
nullptr
Perfect thanks, and for those who come later you do it in NHibernateLambdaExtensions (wasn't asked for but I needed it) like this: distinctQuery.SetProjection(Projections.Distinct(LambdaProjection.Property<Person>(p => p.Country)));
reach4thelasers
If you want more points I just posted a related question at http://stackoverflow.com/questions/1753161/nhibernate-criteria-query-select-distinct-with-joined-entity
reach4thelasers