title: Simplemembership webpages_UsersInRoles code first FK error
body: <p>I'm trying to implement the SimpleMembership entities so I can control some aspects of it, Here are the classes I created:</p>
  
  <pre><code> [Table("webpages_Roles")]
   public class Role
  {
      public Role()
      {
          UsersInRoles = new List&lt;UsersInRole&gt;();
      }
  
      [Key]
      public int RoleId { get; set; }
      [StringLength(256)]
      public string RoleName { get; set; }
  
      //public ICollection&lt;Membership&gt; Members { get; set; }
  
      [ForeignKey("RoleId")]
      public ICollection&lt;UsersInRole&gt; UsersInRoles { get; set; }
  }
  [Table("webpages_UsersInRoles")]
  public class UsersInRole
  {
      [Key, Column(Order = 0)]
      public int RoleId { get; set; }
  
      [Key, Column(Order = 1)]
      public int UserId { get; set; }
  
      [Column("RoleId"), InverseProperty("UsersInRoles")]
      public Role Roles { get; set; }
  
      [Column("UserId"), InverseProperty("UsersInRoles")]
      public Membership Members { get; set; }
  
  
  
  }
   [Table("webpages_Membership")]
  public class Membership
  {
      public Membership()
      {
          //Roles = new List&lt;Role&gt;();
          OAuthMemberships = new List&lt;OAuthMembership&gt;();
          UsersInRoles = new List&lt;UsersInRole&gt;();
      }
  
      [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
      public int UserId { get; set; }
      public DateTime? CreateDate { get; set; }
      [StringLength(128)]
      public string ConfirmationToken { get; set; }
      public bool? IsConfirmed { get; set; }
      public DateTime? LastPasswordFailureDate { get; set; }
      public int PasswordFailuresSinceLastSuccess { get; set; }
      [Required, StringLength(128)]
      public string Password { get; set; }
      public DateTime? PasswordChangedDate { get; set; }
      [Required, StringLength(128)]
      public string PasswordSalt { get; set; }
      [StringLength(128)]
      public string PasswordVerificationToken { get; set; }
      public DateTime? PasswordVerificationTokenExpirationDate { get; set; }
      //public ICollection&lt;Role&gt; Roles { get; set; }
  
      [ForeignKey("UserId")]
      public ICollection&lt;OAuthMembership&gt; OAuthMemberships { get; set; }
  
      [ForeignKey("UserId")]
      public ICollection&lt;UsersInRole&gt; UsersInRoles { get; set; }
  }
  
  [Table("UserProfile")]
  public class UserProfile
  {
      [Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int UserId { get; set; }
      public string UserName { get; set; }
      public bool Status { get; set; }
      public string EmailId { get; set; }
  }
  </code></pre>
  
  <p>Now as soon as I try to insert a new user, it is inserted correctly on the tables userProfile and webpages_Membership but as soon as the application tries to assign a role to the user an exception is thrown</p>
  
  <p>*The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.webpages_UsersInRoles_dbo.webpages_Membership_UserId". The conflict occurred in database "PCSPI", table "dbo.webpages_Membership", column 'UserId'.
  The statement has been terminated.*</p>
  
  <p>I tried to insert it manually with sql server and it inserts but as soon as I try to do it on my application the exception is thrown.</p>
  
  <p>What am I doing wrong? isnt the model well defined?
  Thanks in advance</p>