title: How to add a role to use when EF doesn't bring in UserRoles Table?
body: <p>I have a UserRoles table with just two columns userId and RoleId and entityframework doesn't bring that class in. How can save the association without the userroles class? </p>
  
  <p>my users and roles classes in EntityFramework are like this.</p>
  
  <pre><code>public partial class aspnet_Users
  {
      public aspnet_Users()
      {
          this.aspnet_Roles = new HashSet&lt;aspnet_Roles&gt;();
      }
  
      public System.Guid ApplicationId { get; set; }
      public System.Guid UserId { get; set; }
      public string UserName { get; set; }
      public string LoweredUserName { get; set; }
      public string MobileAlias { get; set; }
      public bool IsAnonymous { get; set; }
      public System.DateTime LastActivityDate { get; set; }
  
      public virtual aspnet_Applications aspnet_Applications { get; set; }
      public virtual aspnet_Membership aspnet_Membership { get; set; }
      public virtual ICollection&lt;aspnet_Roles&gt; aspnet_Roles { get; set; }
  }
  
      public partial class aspnet_Roles
      {
          public aspnet_Roles()
          {
              this.aspnet_Users = new HashSet&lt;aspnet_Users&gt;();
          }
  
          public System.Guid ApplicationId { get; set; }
          public System.Guid RoleId { get; set; }
          public string RoleName { get; set; }
          public string LoweredRoleName { get; set; }
          public string Description { get; set; }
  
          public virtual aspnet_Applications aspnet_Applications { get; set; }
          public virtual ICollection&lt;aspnet_Users&gt; aspnet_Users { get; set; }
      }
  </code></pre>
  
  <p>EF doesn't give me UserRoles class in model but it shows up in XML.</p>
  
  <p>when i try to add a new user, i am accessing like this</p>
  
  <pre><code>                    var role = new Data.aspnet_Roles();
                      role.RoleId = userItem.roles.First().RoleId;
                      role.RoleName = userItem.roles.First().RoleName;
                      user.aspnet_Roles.Add(role);
  </code></pre>
  
  <p>This gives a error</p>
  
  <p>InnerException  {"Cannot insert duplicate key row in object 'dbo.aspnet_Roles' with unique index 'aspnet_Roles_index1'.\r\nThe statement has been terminated."} System.Exception {System.Data.SqlClient.SqlException}</p>
  
  <p>the answer here suggest that it should work. i cant figure out what i am doing wrong.
  <a href="https://stackoverflow.com/questions/26768084/entity-framework-add-user-to-role">Entity Framework Add User to Role</a></p>
  
  <p>It also makes sense that i get this error. But I am clueless on how else i can store the userroles relationship without having userroles EF class.  I am really stuck. Any help is appreciated. Thank you.</p>