how to map composite key in CRUD functionality
The find method, finds entities by the primary key. If you have a composite primary key, then pass the key values in the order they are defined in model:
@Html.ActionLink("Edit", "Edit", new { comp = item.comp, part = item.part }) |
@Html.ActionLink("Details", "Details", new { comp = item.comp, part = item.part }) |
@Html.ActionLink("Delete", "Delete", new { comp = item.comp, part = item.part })
In the controller, receive both values:
public ActionResult Edit(int? comp, int? part)
{
DataView record = db.RecordDataView.Find(comp, part);
if (record == null)
{
return HttpNotFound();
}
return View(record);
}