title: Doing table per subclass using a discriminator with NHibernate.Mapping.Attributes
body: <p>I'm trying to do <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html#inheritance-tablepersubclass-discriminator" rel="nofollow noreferrer">Table per subclass: using a discriminator</a> using NHibernate.Mapping.Attributes.
  The hbm should look like this:</p>
  
  <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt;
    &lt;subclass name="SalesReport" discriminator-value="SalesReport" extends="Report"&gt;
      &lt;join table="SalesReport"&gt;
        &lt;key foreign-key="FK_SalesReport_Document" /&gt;
        &lt;property name="TotalSales" /&gt;
        &lt;property name="NetGrouth" /&gt;
      &lt;/join&gt;
    &lt;/subclass&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>The code looks like this:</p>
  
  <pre><code>[Subclass(NameType=typeof(SalesReport),
      DiscriminatorValueObject=DocumentDiscriminator.SalesReport,
      ExtendsType=typeof(Report))]
  [Serializable]
  public partial class SalesReport : Common.Documents.Report
  {
      [Join(Table = "SalesReport")]
      [Key(1, ForeignKey = "FK_SalesReport_Document")]
      [Property(2)]
      public virtual decimal TotalSales
      {
          get;
          set;
      }
  
      [Join(Table = "SalesReport")]
      [Key(1, ForeignKey = "FK_SalesReport_Document")]
      [Property(2)]
      public virtual decimal NetGrouth
      {
          get;
          set;
      }
  }
  </code></pre>
  
  <p>The result is something like this:</p>
  
  <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt;
    &lt;subclass name="SalesReport" discriminator-value="SalesReport" extends="Report"&gt;
      &lt;join table="SalesReport"&gt;
        &lt;key foreign-key="FK_SalesReport_Document" /&gt;
        &lt;property name="TotalSales" /&gt;
      &lt;/join&gt;
      &lt;join table="SalesReport"&gt;
        &lt;key foreign-key="FK_SalesReport_Document" /&gt;
        &lt;property name="TotalSales" /&gt;
        &lt;property name="NetGrouth" /&gt;
      &lt;/join&gt;
    &lt;/subclass&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>It creates the right table structure (one table with two decimal fields and one PF/FK to Reports table) but when insterting data it failes, because it generetes two inserts for each field:</p>
  
  <pre><code>NHibernate: INSERT INTO SalesReport (TotalSales, SalesReport) VALUES (@p0, @p1);@p0 = 13400,20, @p1 = 41
  NHibernate: INSERT INTO SalesReport (NetGrouth, SalesReport) VALUES (@p0, @p1);@p0 = 0, @p1 = 41
  </code></pre>
  
  <p>Is there a way to get this done using NHibernate.Mapping.Attributes?</p>