title: Fluent NHibernate table-per-class-hierarchy need to use .Where()?
body: <p>I have the following mapping for a set of contact classes based off an abstract Contact class implementation.</p>
  
  <pre><code>   public class ContactMapping : ClassMap&lt;Contact&gt; {
          public ContactMapping() {
              Id(x =&gt; x.Id).GeneratedBy.GuidComb();
              Map(x =&gt; x.CreatedDate).Not.Nullable();
              Map(x =&gt; x.Value).Not.Nullable();
              Map(x =&gt; x.Level).Not.Nullable();
              Map(x =&gt; x.Comments);
              DiscriminateSubClassesOnColumn("ContactType");
          }
      }
  
      public class PhoneContactMapping : SubclassMap&lt;PhoneContact&gt; {
          public PhoneContactMapping() {
              Map(p =&gt; p.PhoneType);
              DiscriminatorValue("PhoneContact");
          }
      }
      public class EmailContactMapping : SubclassMap&lt;EmailContact&gt; {
          public EmailContactMapping() {
              DiscriminatorValue("EmailContact");
          }
  
      }
      public class WebsiteContactMapping : SubclassMap&lt;WebsiteContact&gt; {
          public WebsiteContactMapping() {
              DiscriminatorValue("WebsiteContact");
          }
      }
  </code></pre>
  
  <p>I have an entity class that HasMany EmailContact(s), WebsiteContact(s), and PhoneContact(s).</p>
  
  <pre><code>public class ContactableEntityMapping: ClassMap&lt;ContactableEntity&gt; {
      public ContactableEntityMapping() {
          Id(x =&gt; x.Id).GeneratedBy.GuidComb();
          Map(x =&gt; x.CreatedDate).Not.Nullable();
          Map(x =&gt; x.Comment);
          HasMany&lt;EmailContact&gt;(x =&gt; x.EmailContacts).AsBag().Not.LazyLoad().Where("ContactType='EmailContact'");
          HasMany&lt;PhoneContact&gt;(x =&gt; x.PhoneContacts).AsBag().Not.LazyLoad().Where("ContactType='PhoneContact'");
          HasMany&lt;WebsiteContact&gt;(x =&gt; x.WebsiteContacts).Not.LazyLoad().AsBag().Where("ContactType='WebsiteContact'");
          HasManyToMany(x =&gt; x.Addresses).AsSet();
      }
  }
  </code></pre>
  
  <p>If i do not specify there .Where() clauses the class ends up coming back with all rows mapped to EmailContact (since it is first in the listing) if LazyLoading is used, and if lazy-loading is not used I receive an exception as it attempts to cast the classes to the wrong type.</p>
  
  <p>Obviously this is because the SQL executed is not passing in the additional where clause unless I specify it in the mapping.  Am I missing something in my mapping, or is the Where mess just something we need to live with?</p>
  
  <p>Thanks for the help!</p>