How to update the domain model object based on the domain model parameter passed to Edit action method?

Try this: db.Movies. ApplyCurrentValues(model); db.SaveChanges() You can also just copy values from model to movie: movie. Title = model.

Title; movie. Director = model. Director; db.SaveChanges() OK.

You are using Code First, so it will be probably: var entry = context. Entry(movie); entry.CurrentValues. SetValues(model); db.SaveChanges() But I am not sure about it, because I don't have Code First installed.

Taken from: http://blogs.msdn.com/b/adonet/archive/2011/01/30/using-dbcontext-in-ef-feature-ctp5-part-5-working-with-property-values.aspx.

Try this: db.Movies. ApplyCurrentValues(model); db.SaveChanges(); You can also just copy values from model to movie: movie. Title = model.

Title; movie. Director = model. Director; db.SaveChanges(); OK.

You are using Code First, so it will be probably: var entry = context. Entry(movie); entry.CurrentValues. SetValues(model); db.SaveChanges(); But I am not sure about it, because I don't have Code First installed.

Taken from: http://blogs.msdn.com/b/adonet/archive/2011/01/30/using-dbcontext-in-ef-feature-ctp5-part-5-working-with-property-values.aspx.

Lukled: EF 4 does not have ApplyCurrentValue method. – LaTeX Feb 17 at 3:34 @user596314: Yes it has. – LukLed Feb 17 at 3:37 @Lukled: Your second option is already thought before posting this question.

But it is tedious. – LaTeX Feb 17 at 3:38 @Lukled: Error 1 'System.Data.Entity. DbSet' does not contain a definition for 'ApplyCurrentValue' and no extension method 'ApplyCurrentValue' accepting a first argument of type 'System.Data.Entity.

DbSet' could be found (are you missing a using directive or an assembly reference? ) G:\MVC\MvcMovie\MvcMovie\Controllers\MovieController. Cs 92 23 MvcMov?

Ie – LaTeX Feb 17 at 3:41 @user596314: msdn.microsoft. Com/en-us/library/dd466205. Aspx – LukLed Feb 17 at 3:41.

HttpPost public ActionResult Edit(Movie movie) { if (movie == null) { TempData"MESSAGE" = "No movie with id = " + id + ". "; return RedirectToAction("Index", "Home"); } if (!ModelState. IsValid) return View(movie); // what method do I have to invoke here // to update the movie object based on the model parameter?Db.Movie.

AddObject(movie); db. ObjectStateManager. ChangeObjectState(movie, System.Data.EntityState.

Modified); db.SaveChanges(); return RedirectToAction("Index"); }.

AddObject does not exist in EF 4. – LaTeX Feb 17 at 3:36 1 @user596314 It exists in my version of EF4... I got that from my app code and I am definitely using EF4 – Dr Rob Feb 17 at 3:52 I used EFCodeFirst and am new to EF. By the way, why did you add the movie to the context rather than modify the existing one?

– LaTeX Feb 17 at 4:58 One more, why did you remove the checking parts of my code? If the given id does not correspond to any record in the database, what happens? – LaTeX Feb 17 at 5:00.

B Z: Yes. It works too. – LaTeX Feb 17 at 4:56.

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.

Related Questions