title: How to order a HasMany collection by a child property with Fluent NHibernate mapping
body: <p>I am using Fluent NHibernate to map the following classes:</p>
  
  <pre><code>public abstract class DomainObject
  {
      public virtual int Id { get; protected internal set; }
  }
  
  public class Attribute
  {
      public virtual string Name { get; set; }
  }
  
  public class AttributeRule
  {
      public virtual Attribute Attribute { get; set; }
      public virtual Station Station { get; set; }
      public virtual RuleTypeId RuleTypeId { get; set; }
  }
  
  public class Station : DomainObject
  {
      public virtual IList&lt;AttributeRule&gt; AttributeRules { get; set; }
  
      public Station()
      {
          AttributeRules = new List&lt;AttributeRule&gt;();
      }
  }
  </code></pre>
  
  <p>My Fluent NHibernate mappings look like this:</p>
  
  <pre><code>    public class AttributeMap : ClassMap&lt;Attribute&gt;
      {
          public AttributeMap()
          {
              Id(o =&gt; o.Id);
              Map(o =&gt; o.Name);
          }
      }
  
      public class AttributeRuleMap : ClassMap&lt;AttributeRule&gt;
      {
          public AttributeRuleMap()
          {
              Id(o =&gt; o.Id);
              Map(o =&gt; o.RuleTypeId);
              References(o =&gt; o.Attribute).Fetch.Join();
              References(o =&gt; o.Station);
          }
      }
  
      public class StationMap : ClassMap&lt;Station&gt;
      {
          public StationMap()
          {
              Id(o =&gt; o.Id);
              HasMany(o =&gt; o.AttributeRules).Inverse();
          }
      }
  </code></pre>
  
  <p>I would like to order the AttributeRules list on Station by the Attribute.Name property, but doing the following does not work:</p>
  
  <pre><code>   HasMany(o =&gt; o.AttributeRules).Inverse().OrderBy("Attribute.Name");
  </code></pre>
  
  <p>I have not found a way to do this yet in the mappings. I could create a IQuery or ICriteria to do this for me, but ideally I would just like to have the AttributeRules list sorted when I ask for it.</p>
  
  <p>Any advice on how to do this mapping?</p>