I don't want to put any more code into my controller than I have to.
This works:
//
// POST: /Duty/Edit/5
[HttpPost]
public ActionResult Edit(Duty Model)
{
Duty Attached = (from Duty d in ctx.Duties
where d.Id == Model.Id
select d).Single();
Attached.Designation = Model.Designation;
Attached.Instruction = Model.Instruction;
Attached.OccasionId = Model.OccasionId;
Attached.Summary = Model.Summary;
ctx.UpdateObject(Attached);
ctx.SaveChanges();
return RedirectToAction("Index");
}
But, I don't want to have to type every property.
This fails:
//
// POST: /Duty/Edit/5
[HttpPost]
public ActionResult Edit(Duty Model)
{
ctx.AttachTo("Duty", Model);
ctx.UpdateObject(Model);
ctx.SaveChanges();
return RedirectToAction("Index");
}
It throws a System.Data.Services.Client.DataServiceClientException:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code></code>
<message xml:lang="en-US">Resource not found for the segment 'Duty'.</message>
</error>
Why? How should I write this?