If your sending over your EntityKey Ids from your and simply want to save your posted values then all you need is: edmx.Clients. Attach(client); edmx.SaveChanges().
– mare Mar 15 '10 at 19:54 idk, but thats why I voted him down – jfar Mar 15 '10 at 21:36.
I'm not aware of a nice way to do this. It seems like it should be a case of attaching the edited object and saving changes, but the framework doesn't work that way. In short the SaveChanges magic only works on entity objects that were created from the context you are working with.
Entity objects created by the controller don't qualify. Try something like this (MVC 2 and EF 4) HttpPost public ActionResult Edit(Client clientToEdit) { db.Client. Attach(db.Client.
Single(c => c. ID == clientToEdit. ID)); db.Client.
ApplyCurrentValues(clientToEdit); db.SaveChanges(); } It does require a query in order to update, but I haven't come across a robust way around it. D.
I had to upgrade to 4.0 from 3.5 to make this available but I have it now, however at ApplyCurrentValues there is an exception: "The existing object in the ObjectContext is in the Added state. Changes can only be applied when the existing object is in an unchanged or modified state. " – mare Mar 15 '10 at 16:28 Looks like your Client.
PostCode is a relationship not a scalar property. Changing a relationship puts the object into the 'Added' state. If you call ApplyCurrentValues to update the scalar properties, then change the PostCode it might work.
– Cephas Mar 15 '10 at 23:19.
My form includes a subset of Client entity properties and I also include a hidden field that holds an ID of the client. The client entity itself is provided via the GET Edit action. Now I want to do entity update but so far I've only been trying without first loading the entity from the DB.
Because the client object that comes in POST Edit has everything it needs. I want to update just those properties on the entity in datastore. "The existing object in the ObjectContext is in the Added state.
Changes can only be applied when the existing object is in an unchanged or modified state.".
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.