title: Sorting linked collection in Nhibernate query
body: <p>This is partly related to <a href="https://stackoverflow.com/questions/814510/nhibernate-sorting-a-has-many-collection">this</a>.<br>
  I'd like to find a way to sort of a linked (HasMany) collection result directly in the Nhibernate query.</p>
  
  <pre><code> ICriteria criteria = Session.CreateCriteria(typeof(PortalPage));
   criteria.CreateAlias("PartialViews", "vc");
   criteria.AddOrder(Order.Asc("vc.ColumnNumber"));
   criteria.Add(Property.ForName("Url").Eq(pageUrl));
   return criteria.UniqueResult&lt;PortalPage&gt;();
  </code></pre>
  
  <p>Correcly generates a select with the ORDER BY but the result in the linked collection is not ordered.  </p>
  
  <p>I'd like to avoid sorting the collection after the result is returned (like using linq to objects) is this possible?</p>
  
  <p>UPDATE:
  As Steve suggested the problem can be solved by hard coding the order attribute in the mapping like:</p>
  
  <pre><code>HasMany(x =&gt; x.PartialViews).KeyColumnNames.Add("PageId").AsBag().SetAttribute("order-by", "ColumnNumber");
  </code></pre>