title: How can I add in a batch multiple users to roles with SQL Server LocalDb
body: <p>I have the following code:</p>
  
  <pre><code>    WebSecurity.CreateUserAndAccount("r12345678", "abcdefgh", false);
      WebSecurity.CreateUserAndAccount("m12345678", "abcdefgh", false);
      System.Web.Security.Roles.CreateRole("Author");
      System.Web.Security.Roles.CreateRole("Admin");
      System.Web.Security.Roles.CreateRole("Super");
      System.Web.Security.Roles.AddUserToRole("r12345678", "Author");
      System.Web.Security.Roles.AddUserToRole("r12345678", "Admin");
      System.Web.Security.Roles.AddUserToRole("r12345678", "Super");
      System.Web.Security.Roles.AddUserToRole("m12345678", "Author");
      System.Web.Security.Roles.AddUserToRole("m12345678", "Admin");
  </code></pre>
  
  <p>The first 5 lines work good but then when it comes to this line:</p>
  
  <pre><code>    System.Web.Security.Roles.AddUserToRole("r12345678", "Super");
  </code></pre>
  
  <p>I get the following:</p>
  
  <pre><code>The INSERT statement conflicted with the FOREIGN KEY constraint "webpages_Roles_UserProfiles_Target". The conflict occurred in database "T12345", table "dbo.UserProfile", column 'UserId'.
  The statement has been terminated.
  </code></pre>
  
  <p>I cannot understand why this is. I have a 100% fresh database. In fact I delete the database and recreate. Here's my SQL Definition:</p>
  
  <pre><code>CREATE TABLE [dbo].[webpages_UsersInRoles] (
      [RoleId] INT NOT NULL,
      [UserId] INT NOT NULL,
      PRIMARY KEY CLUSTERED ([RoleId] ASC, [UserId] ASC),
      CONSTRAINT [webpages_Roles_UserProfiles_Source] FOREIGN KEY ([RoleId]) REFERENCES [dbo].[webpages_Roles] ([RoleId]) ON DELETE CASCADE,
      CONSTRAINT [webpages_Roles_UserProfiles_Target] FOREIGN KEY ([UserId]) REFERENCES [dbo].[UserProfile] ([UserId]) ON DELETE CASCADE
  );
  </code></pre>
  
  <p>My UserProfile table Contains:</p>
  
  <pre><code>UserId  UserName
  1   r12345678
  2   m12345678
  </code></pre>
  
  <p>My UsersInRoles table Contains:</p>
  
  <pre><code>RoleId  UserId
  1       1
  1       2
  </code></pre>
  
  <p>My Role table contains:</p>
  
  <pre><code>1   Author
  2   Admin
  3   Super
  </code></pre>
  
  <p>Does anyone have an idea why the Foreign Key constraint is getting triggered</p>
  
  <p>Update:</p>
  
  <p>Note that I tried the following and this did not work either. It gave a similar error:</p>
  
  <pre><code>Roles.AddUsersToRoles(new[] {"r12345678"}, new[] {"Author","Admin","Super"});
  Roles.AddUsersToRoles(new[] {"m12345678" }, new[] { "Author", "Admin", "Super" });
  </code></pre>