开发者

NHibernate Criteria Query - Select Distinct with Joined Entity

开发者 https://www.devze.com 2022-12-11 13:57 出处:网络
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

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?


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消