Hello,
I have an entityframework entity called "ABC" (attributes ID and Title).
On update record view, I have added the ID as hidden field and title is the text box.
Controller looks like something:
public ActionResult UpdateAction( ABC obj )
I get everything fine and fair in obj - i.e., the title, and the ID.
Now to update the record in database, I read the original entity:
var original = (from x in base.context.ABC where x.id == obj.id ).Single();
Now to reflect the changes in original, I think should do the update model:
this.TryUpdateModel( original );
I get an error :| ... stating that column ID cannot be changed.
The property 'id' is part of the object's key information and cannot be modified.
I do not want to manually assign the properties back to original object.
The other alternative can be:
TryUpdateModel(original, new string[] { "Title" }, form.ToValueProvider());
But I hate strings - also, my object has like 20 attributes :|
Can someone please suggest a better pattern of doing so?
Rgds