title: Distinct Paged List<Object> sorted on joined table
body: <p>Been trying to get the following working using nhibernate HQL or QueryOver. I am trying to get a sorted DISTINCT list of the entity organisation while sorting on joined tables and using paging.
  Entities are (shortened version):</p>
  
  <p>Organisation</p>
  
  <pre><code> OrganisationId
   Name
   StatusId
   SubstatusId
  </code></pre>
  
  <p>Address</p>
  
  <pre><code> AddressId
   OrganisationId
   City
   CountryId
  </code></pre>
  
  <p>ListItem</p>
  
  <pre><code> ListItemId
   Name
  </code></pre>
  
  <p>StatusId, SubstatusId and CountryId are foreign keys to ListItemId
  ListItemId is a list of user entered options.
  There can be more than one address for each organisation</p>
  
  <p>To sort on Organisation.Address[x].Country.Name I need to include this in the select, but obviously then I dont get distinct organisations rather distinct organisations for a particular address.</p>
  
  <p>I cant then get this into the nHibernate entity as it has the additional Country.Name field.</p>
  
  <p>Also I cant run another distinct over the initial results as im using .SetFirstResult and .SetMaxResults to do SQL Paging.
  If I only want 10 rows, then I initially get 10 rows of distinct (organisation + country name).
  When i run another distinct over this will get reduced if an organisation has more than address.</p>
  
  <p>Any ideas how to get a distinct paged list of organisations while sorting on Address.Name, Status.Name, SubStatus.Name</p>