title: Mapping Parent and Child Tables with Fluent NHibernate
body: <p>Hi have the following tables defined in my database:</p>
  
  <pre><code>Transactions:
  - TransactionID (PK, Identity)
  - TypeID (FK)
  - Amount
  
  TransactionTypes:
  - TypeID (PK, Identity)
  - Type
  
  ProductTransactions:
  - TransactionID (PK)
  - Discount
  </code></pre>
  
  <p>There are 2 types of transactions (Events and Products).  Products have an additional Discount field so an additional table is defined.</p>
  
  <p>I now have the following entities:</p>
  
  <pre><code>public class Transaction
  {
      public virtual int TransactionID { get; private set; }
      public virtual TransactionType Type { get; set; }
      public virtual decimal Amount { get; set; }
  }
  
  public class ProductTransaction : Transaction
  {
      public virtual decimal Discount { get; set; }
  }
  
  public enum TransactionType
  {
      Event = 1,
      Product = 1
  }
  </code></pre>
  
  <p>Finally my mappings are as follows:</p>
  
  <pre><code>public TransactionMap()
  {
      Table("Transactions");
      Id(x =&gt; x.TransactionID);
      Map(x =&gt; x.Amount);
      DiscriminateSubClassesOnColumn("TypeID")
          .SubClass&lt;ProductTransaction&gt;(TransactionType.Product, x =&gt; x.References(y =&gt; y.Type));
  }
  
  public ProductTransactionMap()
  {
      Table("ProductTransactions");
      Map(x =&gt; x.Discount);
  }
  </code></pre>
  
  <p>I'd like to be able to say the following to insert a product transaction:</p>
  
  <pre><code>productRepository.Insert(new ProductTransaction { Type = TransactionType.Product, Amount = 100m, Discount = 10m });
  </code></pre>
  
  <p>However there is something wrong with my mapping.  I'm sure my problem revolves around the DiscriminateSubClassesOnColumn bit but i'm abit lost with what to put here.  I'd really appreciate it if someone could show me how this could be done.  Thanks</p>