Entity Framework with ASP.NET MVC. Updating entity problem?

Ok people, I just found out how it can be solved. Instead of setting the whole object in the Category property, it is necessary to set only the entity key in the reference property So, this is wrong: AcceptVerbs(HttpVerbs. Post) public ActionResult Edit(Car car) { var category = context.Categories.

Where(c => c. Id == car.Category. Id).First(); car.

Category = category; context. UpdateCar(car); context.SaveChanges(); return RedirectToAction("Index"); } And this is the right way: AcceptVerbs(HttpVerbs. Post) public ActionResult Edit(Car car) { var category = context.Categories.

Where(c => c. Id == car.Category. Id).First(); car.

CategoryReference. EntityKey = category. EntityKey; context.

UpdateCar(car); context.SaveChanges(); return RedirectToAction("Index"); }.

Ok people, I just found out how it can be solved. Instead of setting the whole object in the Category property, it is necessary to set only the entity key in the reference property. So, this is wrong: AcceptVerbs(HttpVerbs.

Post) public ActionResult Edit(Car car) { var category = context.Categories. Where(c => c. Id == car.Category.Id).First(); car.

Category = category; context. UpdateCar(car); context.SaveChanges(); return RedirectToAction("Index"); } And this is the right way: AcceptVerbs(HttpVerbs. Post) public ActionResult Edit(Car car) { var category = context.Categories.

Where(c => c. Id == car.Category.Id).First(); car. CategoryReference.

EntityKey = category. EntityKey; context. UpdateCar(car); context.SaveChanges(); return RedirectToAction("Index"); }.

Ok people, I just found out how it can be solved. Instead of setting the whole object in the Category property, it is necessary to set only the entity key in the reference property.

That will have the entity modified on only those properties that you explicitly map. Hope this helps! NET Developer (ASP.NET, MVC, WPF) MCTS .

So I need a solution with I no need to assing just updated fields got from view and rest of unassing fields get it from as it is as per available in previous value. I understand and I have the same problem as you. It can be done by using some value!

=null approach but also, sometimes null is a valid value.

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