title: Entity Framework and generics
body: <p>I have a couple independent objects, each of which has a list of a common object. For instance,</p>
  
  <pre><code>public class Project 
  { 
     public IEnumerable&lt;CommentEntry&lt;Project&gt;&gt; Comments{get;set;}
  }
  public class Sample
  { 
     public IEnumerable&lt;CommentEntry&lt;Sample&gt;&gt; Comments{get;set;}
  }
  public class CommentEntry&lt;T&gt; where T: class
  { 
     public int TId {get;set;}
     public int CommentEntryId{get;set;}
     public DateTime TimeStamp{get;set;}
     public string Comment{get;set;}
  }
  </code></pre>
  
  <p>Using fluent api of Entity Framework 5, I would like a CommentEntry table for Projects and Requests. So, here is my mapping code:</p>
  
  <pre><code>modelBuilder.Entity&lt;CommentEntry&lt;Project&gt;&gt;()
              .Map(m =&gt;
                  {
                      m.ToTable("EngineeringProjectComments");
                  });
          modelBuilder.Entity&lt;CommentEntry&lt;Request&gt;&gt;()
              .Map(m =&gt;
              {
                  m.ToTable("SampleRequestComments");
              });
  </code></pre>
  
  <p>When I attempt my migration I encounter the following message:</p>
  
  <p>The type CommentEntry`1[Project]' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.</p>
  
  <p>I can see the obvious flaw of my attempt to use generics in this context. However, can anyone suggest an alternative to my database table structure, classes code or mapping code that will allow me to share the single, generic type among many classes and have independent tables?</p>