0
In an application I am developing, when trying to update only the fields that were changed the Entity Framework is also changing the fields that do not need.
Repository code:
public void Update(T entity)
{
m_Context.Entry(entity).State = EntityState.Modified;
}
Controller code:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(BlogViewModel model)
{
if (ModelState.IsValid)
{
using (var context = new UnitOfWork())
{
var blogDomain = Mapper.Map<BlogViewModel, Blog>(model);
blogDomain.DateEdited = DateTime.Now;
context.BlogRepository.Update(blogDomain);
context.SaveChanges();
return RedirectToAction("Index");
}
}
return View(model);
}
I would like a help to solve this problem.
You can bring the entity and change only the fields you need, the way you did it is really changed. !!!
– novic