I'm trying to set up an MVC2 app with Entity Framework Self-Tracking-Entities. My view is a strongly-typed view of the entity type generated by the STE T4 template. Here's my GET:
public ActionResult Edit(int id)
{
var ri = new App1Service.App1Client().GetMyObj(id);
var changeTracking = ri.ChangeTracker.ChangeTrackingEnabled; // this shows true
return View(ri);
}
So far, so good. When this form POSTs, however, ChangeTracker is null / reset to default values, and thus, the STE seems suddenly to forget that it's supposed to be tracking itself:
[HttpPost]
public ActionResult Edit(MyObj ri)
{
// MyObj.ChangeTracker.ChangeTrackingEnabled now shows false
// so the following line doesn't save anything:
new App1Service.App1Client().SaveMyObj(ri);
return RedirectToAction("Index");
}
What's the secret to getting the strongly-typed-view to hang onto (and POST back) the whole STE? If I have to go and do another read to get original values and then apply changes, that seems to defeat the purpose of self-tracking-entities, doesn't it?