title: Number of primary key values passed must match key values defined on the entity
body: <p>I have a table for a user to be in a role, it is only one of two roles that the user can be in. </p>
  
  <pre><code>CREATE TABLE [dbo].[webpages_UsersInRoles] (
      [UserId] INT NOT NULL,
      [RoleId] INT NOT NULL,
      CONSTRAINT [PK_dbo.webpages_UsersInRoles] PRIMARY KEY CLUSTERED ([UserId] ASC, [RoleId] ASC),
      CONSTRAINT [FK_dbo.webpages_UsersInRoles_dbo.webpages_Roles_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [dbo].[webpages_Roles] ([RoleId]) ON DELETE CASCADE
  );
  CREATE TABLE [dbo].[webpages_Roles] (
      [RoleId]                     INT            IDENTITY (1, 1) NOT NULL,
      [RoleName]                   NVARCHAR (MAX) NULL,
      [webpages_Membership_UserId] INT            NULL,
      CONSTRAINT [PK_dbo.webpages_Roles] PRIMARY KEY CLUSTERED ([RoleId] ASC),
      CONSTRAINT [FK_dbo.webpages_Roles_dbo.webpages_Membership_webpages_Membership_UserId] FOREIGN KEY ([webpages_Membership_UserId]) REFERENCES [dbo].[webpages_Membership] ([UserId])
  );
  </code></pre>
  
  <p>In my code I am trying to remove a user from <code>UsersInRoles</code> however I keep getting an error back from my tempdata:</p>
  
  <blockquote>
    <p>Error occurred with roles.The number of primary key values passed must
    match number of primary key values defined on the entity. Parameter
    name: key Values</p>
  </blockquote>
  
  <p>This is the code I am using:</p>
  
  <pre><code>        string pid = form["pid"];
  
          try
          {
                  if (ModelState.IsValid)
                  {
                  Provider cprovider = _db.Providers.Find(pid);
                  var UserId = cprovider.UserProfileId;
  
  
                  try
                  {
                      webpages_Membership cmembership = _db.webpages_Memberships.Find(UserId);
                      _db.webpages_Memberships.Remove(cmembership);
                      _db.SaveChanges();
                  }
                  catch (Exception ex)
                  {
                      TempData["Message"] = "Error occured with membership." + ex.Message;
                  }
                  try
                  {
                      UserProfile cprofile = _db.UserProfiles.Find(UserId);
                      _db.UserProfiles.Remove(cprofile);
                      _db.SaveChanges();
                  }
                  catch (Exception ex)
                  {
                      TempData["Message"] = "Error occured with profile." + ex.Message;
                  }
                  try // this code is causing an exception
                  {
                      webpages_UsersInRoles croles = _db.webpages_UsersInRoles.Find(UserId);
                      _db.webpages_UsersInRoles.Remove(croles);
                      _db.SaveChanges();
                  }
                  catch (Exception ex)
                  {
                      TempData["Message"] = "Error occured with roles." + ex.Message;
                  }
  
  
                  cprovider.UserProfileId = null;
                  cprovider.PendingActivation = null;
                  cprovider.Activated = null;
                  cprovider.Email = null;
  
  
                      _db.Entry(cprovider).State = EntityState.Modified;
                      _db.SaveChanges();
                  }
              }
  </code></pre>