title: "The number of primary key values passed must match number of primary key values defined on the entity. Parameter name: keyValues" Entity Framework
body: <p>So Iv'e used the CRUD operations with Entity Framework in my ASP.NET MVC application. I have made a login form where every unique user gets a UserId, and im trying now to manipulate these CRUD operations so the user can edit or delete it's database record. But I keep getting the error as you see in the title.</p>
  
  <p>I think that it has to do with my primary keys, here's some code:</p>
  
  <p>Model:</p>
  
  <pre><code>public partial class TimesheetEntry
      {
          [Key]
          [Column(Order = 0)]
          [DatabaseGenerated(DatabaseGeneratedOption.None)]
          public int UserId { get; set; }
  
          [Key]
          [Column(Order = 1)]
          [StringLength(50)]
          public string ProjectId { get; set; }
  
          [Key]
          [Column(Order = 2, TypeName = "date")]
          public DateTime EntryDate { get; set; }
  
          public decimal HoursWorked { get; set; }
  
          public virtual Project Project { get; set; }
  
          public virtual User User { get; set; }
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model IEnumerable&lt;Aviato.Models.TimesheetEntry&gt;
  
  @{
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create", "Create")
  &lt;/p&gt;
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.UserId)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Project.ProjectName)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.EntryDate)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.HoursWorked)
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
      @foreach (var item in Model) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.UserId)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Project.ProjectName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.EntryDate)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.HoursWorked)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.ActionLink("Edit", "Edit", new { id=item.UserId }) |
                  @Html.ActionLink("Details", "Details", new { id=item.UserId }) |
                  @Html.ActionLink("Delete", "Delete", new { id=item.UserId })
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  
  &lt;/table&gt;
  &lt;div&gt;
      @Html.ActionLink("Index", "Index", "User")
  &lt;/div&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public class TimesheetEntryController : Controller
      {
      private readonly AviatoModel _db = new AviatoModel(); //Database Model
  
      public ActionResult Edit(int? id)
              {
                  if (id == null)
                  {
                      return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                  }
  
                  var timesheetentry = _db.TimesheetEntries.Find(id);
  
                  if (timesheetentry == null)
                  {
                      return HttpNotFound();
                  }
  
                  ViewBag.ProjectId = new SelectList(_db.Projects, "ProjectId", "ProjectName", timesheetentry.ProjectId);
                  ViewBag.UserId = new SelectList(_db.Users, "UserId", "SocialSecurityNumber", timesheetentry.UserId);
  
                  return View(timesheetentry);
              }
  
              [HttpPost]
              public ActionResult Edit([Bind(Include="UserId,ProjectId,EntryDate,HoursWorked")] TimesheetEntry timesheetentry)
              {
                  if (ModelState.IsValid)
                  {
                      _db.Entry(timesheetentry).State = System.Data.Entity.EntityState.Modified;
                      _db.SaveChanges();
                      return RedirectToAction("Index");
                  }
  
                  ViewBag.ProjectId = new SelectList(_db.Projects, "ProjectId", "ProjectName", timesheetentry.ProjectId);
                  ViewBag.UserId = new SelectList(_db.Users, "UserId", "SocialSecurityNumber", timesheetentry.UserId);
  
                  return View(timesheetentry);
              }
  }
  </code></pre>
  
  <p>Database Table:</p>
  
  <pre><code>CREATE TABLE [dbo].[TimesheetEntries] (
      [UserId]      INT            NOT NULL,
      [ProjectId]   NVARCHAR (50)  NOT NULL,
      [EntryDate]   DATE           NOT NULL,
      [HoursWorked] DECIMAL (8, 1) CONSTRAINT [DF_TimesheetEntries_HoursWorked] DEFAULT ((0.0)) NOT NULL,
      CONSTRAINT [PK_TimesheetEntries] PRIMARY KEY CLUSTERED ([UserId] ASC, [ProjectId] ASC, [EntryDate] ASC),
      CONSTRAINT [FK_TimesheetEntries_Users] FOREIGN KEY ([UserId]) REFERENCES [dbo].[Users] ([UserId]),
      CONSTRAINT [FK_TimesheetEntries_Projects] FOREIGN KEY ([ProjectId]) REFERENCES [dbo].[Projects] ([ProjectId])
  );
  </code></pre>
  
  <p>So, how shall I make it possible for the user to change it's own unique data in the database?</p>
  
  <p>Please help.</p>