NHibernate Criteria Query - Select Distinct
Asked Answered
G

1

7

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?

Grapple answered 18/11, 2009 at 1:10 Comment(0)
J
15
criteria.SetProjection(Projections.Distinct(Projections.Property("Country")));
Johnette answered 18/11, 2009 at 1:12 Comment(2)
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)));Grapple
If you want more points I just posted a related question at #1753661Grapple

© 2022 - 2024 — McMap. All rights reserved.