In an application I'm developing, when trying to perform the update only on the fields that have been 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 an aid to solve this problem.