title: Help Fluent NHibernate Mapping a Generic Class
body: <p>I'm hoping somebody can help me with this, I'm trying to write the mapping classes for a class that is subclassed into a generic class. Its easier to descibe with code, so here is my model...</p>
  
  <pre><code>public abstract class TagBase
  {
      public virtual int Id { get; private set; }
      public virtual TagTypeEnum TagType { get; set; }
      public virtual string Value { get; set; }
      public virtual bool IsSystemTag { get; private set; }
      public virtual bool isDeleted { get; set; }
  
      public TagBase()
      {
      }
  
      public TagBase(TagTypeEnum tagType)
      {
          this.TagType = tagType;
      }
  
      public override string ToString()
      {
          return Value;
      }
  }
  
  public class Tag&lt;TLinkedItem&gt; : TagBase where TLinkedItem : ITagged&lt;TLinkedItem&gt;
  {
      public virtual List&lt;TLinkedItem&gt; LinkedItems { get; set; }
  }
  </code></pre>
  
  <p>As you can see <code>Tag</code> is generic but is constrained to only those classes that implement <code>ITagged&lt;T&gt;</code></p>
  
  <p>The idea is that an entity has Tags and in turn a tag has a list of LinkedItems that are strongly typed.</p>
  
  <p>Tags cannot be shared amongst different types of entity</p>
  
  <p>I only have two entities in my model that support tagging so far thay are <code>Display</code> and <code>Asset</code></p>
  
  <p>I've tried to map this with the following Fluent NHibernate code;</p>
  
  <pre><code>public class TagBaseMap : ClassMap&lt;TagBase&gt;
  {
      public TagBaseMap()
      {
          Table("Tag");
          Id(tag =&gt; tag.Id);
          Map(tag =&gt; tag.Value).Not.Nullable().Length(50);
          Map(tag =&gt; tag.IsSystemTag).Not.Nullable();
          Map(tag =&gt; tag.isDeleted).Not.Nullable();
          Map(tag =&gt; tag.TagType).CustomType&lt;Int32&gt;().Not.Nullable();
      }
  }
  
  public class DisplayTagMap : SubclassMap&lt;Tag&lt;Display&gt;&gt;
  {
      public DisplayTagMap()
      {
          HasManyToMany(displayTag =&gt; displayTag.LinkedItems).Inverse().Table("DisplayTagLink");
      }
  }
  
  public class AssetTagMap : SubclassMap&lt;Tag&lt;Asset&gt;&gt;
  {
      public AssetTagMap()
      {
          HasManyToMany(assetTag =&gt; assetTag.LinkedItems).Inverse().Table("AssetTagLink");
      }
  }
  </code></pre>
  
  <p>When I try and build the database, I'm targetting Sql Server, from this mapping I'm getting this error <b>"Incorrect syntax near '`'."</b></p>
  
  <p>Am I right in thinking caused by .Net's naming of generic classes ie, </p>
  
  <p>'{[<b>Model.Tag'1</b>[[Model.Asset, Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].LinkedItems, NHibernate.Mapping.Bag(<b>Model.Tag'1</b>[[Model.Asset, Saturn.ConnectVision.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].LinkedItems)]}'</p>
  
  <p>Am I doing something daft here?</p>
  
  <p>Is there a way around this problem?</p>
  
  <p>Thanks in advance for any advice.</p>