title: Order By nHibernate Causes 'Antlr.Runtime.NoViableAltException'
body: <p>I get the following error</p>
  
  <blockquote>
    <p>Exception of type 'Antlr.Runtime.NoViableAltException' was thrown.
    [.OrderBy[ORM.Entities.Core.Message,System.DateTime](.Where[ORM.Entities.Core.Message](NHibernate.Linq.NhQueryable`1[ORM.Entities.Core.Message],
    Quote((x, ) =>
    (AndAlso(AndAlso(String.op_Equality(x.ConcerningItemType, p1),
    Equal(x.ConcerningItemId, p2)), OrElse(Equal(x.Sender.Id, p3),
    .Any[ORM.Entities.Core.MessageRecipient](x.Recipients, (r, ) =>
    (Equal(r.Employee.Id, p4)), ))))), ), Quote((x, ) =>
    (.FirstORM.Entities.Core.AuditGroup.Created)), )]</p>
  </blockquote>
  
  <p>When I have a IQueryable result set (having just applied some logic to it) and then I try to order it by a child properties variable before calling ToList()</p>
  
  <pre><code>var results = query.Where(x =&gt; x.ConcerningItemType == "1422" &amp;&amp; x.ConcerningItemId == EnquiryId &amp;&amp; //Messages for this Enquiry
                              (x.Sender.Id == EmployeeId || x.Recipients.Any(r =&gt; r.Employee.Id == EmployeeId)));
  </code></pre>
  
  <p>Then I try to order which causes a error</p>
  
  <pre><code>var results2 = results.OrderBy(x =&gt; x.AuditGroup.First().Created).ToList();
  </code></pre>
  
  <p>If I do the following instead I don't get a error (move the tolist to force it to hit the database)</p>
  
  <pre><code>var results3 = results.ToList().OrderBy(x =&gt; x.AuditGroup.First().Created);
  </code></pre>
  
  <hr>
  
  <p>Ask requested more information</p>
  
  <p>AuditGroup Class</p>
  
  <pre><code>    public class AuditGroup : Entity
  {
      public virtual string Guid { get; set; }
      public virtual string PageName { get; set; }
      public virtual string ControlId { get; set; }
      public virtual string ItemType { get; set; }
      public virtual int ItemId { get; set; }
      public virtual int EmployeeId { get; set; }
      public virtual string IPAddress { get; set; }
      public virtual string Parameters { get; set; }
      public virtual DateTime Created { get; set; }
  
  }
  </code></pre>
  
  <p>Message Class</p>
  
  <pre><code>    public class Message : Entity
  {
      // This class represents the standard address fields, for reuse in other entities
      // 
      public virtual int Id { get; set; }
      public virtual int ConcerningItemId { get; set; }
      public virtual String ConcerningItemType { get; set; }
      public virtual String Subject { get; set; }
      public virtual String Body { get; set; }
      public virtual int RecipientCount { get; set; }
      public virtual String RowStatus { get; set; }
  
      public virtual Employee Sender { get; set; }
      public virtual ICollection&lt;MessageRecipient&gt; Recipients { get; set; }
  
      //eww have to do this to be able to access the created date of the message (stored in AuditGroup... Stupidly!)
      public virtual ICollection&lt;AuditGroup&gt; AuditGroup { get; set; }
  }
  </code></pre>
  
  <p>Messages Mapping</p>
  
  <pre><code>        public MessageMapping()
      {
          Id(x =&gt; x.Id).Column("MessageId");
          Map(x =&gt; x.ConcerningItemId).Nullable().Column("ItemId");
          Map(x =&gt; x.ConcerningItemType).Nullable().Column("ItemType");
  
          Map(x =&gt; x.Subject).Nullable();
          Map(x =&gt; x.Body);
          Map(x =&gt; x.RecipientCount).Column("MessageRecipientCount");
          Map(x =&gt; x.RowStatus).Column("MessageRowStatus");
  
          References(x =&gt; x.Sender).Column("EmployeeId");
          HasMany(x =&gt; x.Recipients).KeyColumn("MessageId");
  
          //AuditGroup has ItemId-ItemType Needs to map to MessageId-ItemType
          HasMany(x =&gt; x.AuditGroup).KeyColumn("ItemId").Where("ItemType = '1419'");
      }
  </code></pre>