title: Is it possible to directly reference a many-to-many table using entity framework, code first
body: <p>I am using the entity framework and modelling a many-to-many relationship.</p>
  
  <p>I have created the relationship between the two entities using the fluent API (let's say users and groups):</p>
  
  <pre><code>this.HasMany(t =&gt; t.Users)
  .WithMany(t =&gt; t.Groups)
  .Map(
  m =&gt;
  {
    m.ToTable("GroupMembers");
    m.MapLeftKey("Group_Id");
    m.MapRightKey("User_Id");
  });
  </code></pre>
  
  <p>This works great, but I'd like to also be able to reference the GroupMembers table directly.  To do that, I have something like:</p>
  
  <pre><code>[Table("GroupMembers")]
  public class GroupMember
  {
      #region Properties
  
      /// &lt;summary&gt;
      /// Gets or sets the group.
      /// &lt;/summary&gt;
      public virtual Group Group { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the Id of rht group.
      /// &lt;/summary&gt;
      [Key]
      [Column("Group_Id", Order = 1)]
      public int GroupId { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the user.
      /// &lt;/summary&gt;
      public virtual User User { get; set; }
  
      /// &lt;summary&gt;
      /// Gets or sets the Id of the user.
      /// &lt;/summary&gt;
      [Key]
      [Column("User_Id", Order = 2)]
      public int UserId { get; set; }
  
      #endregion
  }    
  </code></pre>
  
  <p>However, I will get the following error during initializing of the DbContext:</p>
  
  <blockquote>
    <p>Schema specified is not valid. Errors:  (381,6) : error 0019: The
    EntitySet 'GroupUser' with schema 'dbo' and table 'GroupMembers' was
    already defined. Each EntitySet must refer to a unique schema and
    table.</p>
  </blockquote>
  
  <p>I believe this is because the entity framework does not realize that the GroupMembers table specified in the fluent API and the GroupMembers entities table are actually one in the same.  In other words, if I remove the fluent API code which is describing the many-to-many relationship, then I am successfully able to initialize the DbContext.</p>
  
  <p>Can I have a many-to-many table that I can also reference directly?</p>