NHibernate Criteria Query - Select Distinct with J

2020-04-15 11:21发布

I have a Person entity. Every person has a country, I want to select all the distinct countries that have people in them. This Criteria Query returns all the distinct CountryID's

criteria.SetProjection(Projections.Distinct(Projections.Property("Country")));

How do I alter it to join and fetch the Country entity, not just the ID?

1条回答
乱世女痞
2楼-- · 2020-04-15 11:52

Any easy way would be to use a subquery. That is, you could select the whole country on the outer query where the country ID matches the inner query.

Subqueries.PropertyIn(
  "Country",
  innerDetachedCriteriaWhichFindsCountriesWithPeopleAndProjectsCountryId)
查看更多
登录 后发表回答