NHibernate Criteria Query - Select Distinct

reach4thelasers picture reach4thelasers · Nov 18, 2009 · Viewed 9.9k times · Source

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?

Answer

Derek Slager picture Derek Slager · Nov 18, 2009
criteria.SetProjection(Projections.Distinct(Projections.Property("Country")));