title: nHibernate Per table class map, formula reference parent preoperty
body: <p><strong>TL;DR</strong></p>
  
  <p>Take the "Subclasses" example from here </p>
  
  <p><a href="https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping" rel="nofollow">https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping</a>.  </p>
  
  <p>I want to have a formula in <code>ChildMap</code> that uses the <code>Name</code> property of <code>Parent</code></p>
  
  <p><strong>Long Details</strong></p>
  
  <p>I have an inheritance hierarchy (<code>Product</code> -> <code>StockProduct</code>, <code>KitProduct</code>, <code>ListingProduct</code>, <code>VariationParentProduct</code>) with an Inventory_Product table holding all the common fields, and <code>Inventory_StockProduct</code>/<code>Inventory_KitProduct</code> etc with the specific fields for the sub-class.  I believe this is called sub-class table mapping.  </p>
  
  <p>On my base class <code>Product</code> I have a property called <code>ProductType</code>.  </p>
  
  <pre><code>public abstract class Product
  {
      public virtual Guid ProductID { get; set; }
  
      public abstract ProductType ProductType { get; }
  
      public virtual int AvailableQuantity { get; set; }
  }
  
  public class StockProduct : Product
  {
      // Some other fields
      public override ProductType ProductType
      {
          get { return ProductType.Stock; }
      }
  }
  
  public class KitProduct : Product
  {
      // Some other fields
      public override ProductType ProductType
      {
          get { return ProductType.Kit; }
      }
  }
  
  public class ListingProduct : Product
  {
      // Some other fields
      public override ProductType ProductType
      {
          get { return ProductType.Listing; }
      }
  }
  
  public class VariationParentProduct : Product
  {
      // Some other fields
      public override ProductType ProductType
      {
          get { return ProductType.VariationParent; }
      }
  }
  
  public enum ProductType
  {
      Stock = 0,
      Kit = 1,
      Listing = 2,
      VariationParent = 3
  }
  </code></pre>
  
  <p>And the mappings</p>
  
  <pre><code>public class ProductMap : ClassMap&lt;Product&gt;
  {
     public ProductMap()
      {
          Table("Inventory_Products");
  
          Id(x =&gt; x.ProductID).GeneratedBy.Guid();
          Map(x =&gt; x.Sku);
  
          Map(x =&gt; x.ProductType).CustomType&lt;ProductType&gt;().Access.ReadOnly();
      }
  }
  
  public class StockProductMap : SubclassMap&lt;StockProduct&gt;
  {
      public StockProductMap()
      {
          Table("Inventory_StockProducts");
  
          KeyColumn("ProductID");
  
          Map(x =&gt; x.AvailableQuantity).Formula("(CASE ProductType WHEN 0 THEN (1) ELSE NULL END)");
      }
  }
  
  public class KitProductMap : SubclassMap&lt;KitProduct&gt;
  {
      public KitProductMap ()
      {
          Table("Inventory_KitProducts");
  
          KeyColumn("ProductID");
  
          Map(x =&gt; x.AvailableQuantity).Formula("(CASE ProductType WHEN 0 THEN (2) ELSE NULL END)");
      }
  }
  </code></pre>
  
  <p>I need to somehow get access to this in a formula defined on the <code>StockProduct</code>/<code>KitProduct</code> to do different SQL </p>
  
  <p>I have tried on <code>StockProduct</code></p>
  
  <pre><code>Map(x =&gt; x.AvailableQuantity).Formula("(CASE ProductType WHEN 0 THEN (1) ELSE NULL END)") 
  </code></pre>
  
  <p>and KitProduct</p>
  
  <pre><code>Map(x =&gt; x.AvailableQuantity).Formula("(CASE ProductType WHEN 1 THEN (2) ELSE NULL END)") 
  </code></pre>
  
  <p>But nhibernate prefixes <code>ProductType</code> with the table alias for [<code>KitProduct</code>|<code>StockProduct</code>] rather than the base product. So the column its referencing doesn't exist</p>
  
  <p>Is there an equivalent to <code>this.</code> in a formula for the parent object?</p>