title: NHibernate - map a property of a runtime-defined type
body: <p>Alright, so I need to create a couple of tables, which need to be almost identical except for one field.</p>
  
  <p>My model would roughly look like this:</p>
  
  <pre><code>class HouseGeometryModel
  {
     public virtual int Id { get; set; }
     public virtual string Name { get; set; }
     //More fields...
  
     public virtual HouseAttributes Attributes { get; set; }
  }
  
  class DungeonGeometryModel
  {
     public virtual int Id { get; set; }
     public virtual string Name { get; set; }
     //More fields, all identical to HouseGeometryModel...
  
     public virtual DungeonAttributes Attributes { get; set; }
  }
  
  class FortressGeometryModel
  {
     public virtual int Id { get; set; }
     public virtual string Name { get; set; }
     //More fields, all identical to HouseGeometryModel...
  
     public virtual FortressAttributes Attributes { get; set; }
  }
  
  //More models...
  </code></pre>
  
  <p>So, basically only the <code>Attributes</code> property differs between all the models here, so I thought there could be a way to unify everything into a single (generic?) class.</p>
  
  <p>I could come up with two ways to implement this:</p>
  
  <ol>
  <li><p>Make a generic class <code>GeometryModel&lt;TAttributes&gt;</code> which would look like:</p>
  
  <pre><code>class GeometryModel&lt;TAttributes&gt;
  {
      public virtual int Id { get; set; }
      public virtual string Name { get; set; }
      //More fields...
  
      public virtual TAttributes Attributes { get; set; }
  }
  </code></pre>
  
  <p>The problem with this is that I fail to specify a fluent mapping. The mapping should also become generic this way (to implement <code>ClassMap&lt;GeometryModel&lt;TAttributes&gt;&gt;</code>) and therefore it would be impossible to instantiate it with NHibernate.</p></li>
  <li><p>Make the <code>Attributes</code> property <code>dynamic</code>. It doesn't work either because NHibernate treats <code>dynamic</code> properties as <code>object</code> when creating a <code>ClassMap&lt;&gt;</code>.</p></li>
  </ol>
  
  <p>Is there any solution to this? </p>