title: NHibernate: Fetch an association which exists only in a subclass of the Query<>'d type
body: <p>I've got a table-per-subclass setup using NHibernate &amp; I'm trying to construct a LINQ query which pre-fetches certain properties that can exist in the derived classes, but I just can't work out how to write the query. E.g. Something like:</p>
  <pre><code>var elements = session.Query&lt;Element&gt;()
          .Fetch(e =&gt; e.Design) // Fine, resides in Element
        //.Fetch(e =&gt; (e as Material)?.Category)
        //.Fetch(e =&gt; (e as Operational)?.EnergySource)
          .Where(e =&gt; elementIdList.Contains(e.Id)) // Or similar query
  </code></pre>
  <p>Obviously the above won't work; I need a statement that can actually be converted to SQL -- How can I explicitly instruct NHibernate to fetch a derived class' associations? I.e. Assume in the following classes that <code>Design</code>, <code>Category</code> and <code>EnergySource</code> have <code>&lt;many-to-one&gt;</code> relationships from their corresponding &quot;Elements&quot;</p>
  <pre><code>public class Element
  {
      public virtual int Id { get; set; }
      public virtual Design Design { get; set; }
  }
  
  public class Material : Element
  {
      public virtual Category Category { get; set; }
  }
  
  public class Operational : Element
  {
      public virtual EnergySource EnergySource { get; set; }
  }
  </code></pre>
  <p>I can emulate it using <code>ToFuture</code> queries on both subclasses &amp; then merging the results, or with an appropriate default config + <code>QueryOver&lt;&gt;</code>, but trying to work out how to do this with <code>Query&lt;&gt;</code>.</p>