I am managing a project with MVC
and EF 6.2
, in my model I have an entity that has four fields:
public class Entidad
{
public string campo1 {get; set;}
public string campo2 {get; set;}
public string campo3 {get; set;}
public string campo4 {get; set;}
}
My class of DAO
has the update method as follows:
public void actualizar(Entidad entidad)
{
using(var context = new DbContext())
{
context.Entry(entidad).State = EntityState.Modified;
context.SaveChanges();
}
}
However, when the update method is passed as an entity parameter with four fields set ( field1, field2, field3 and field4 ), the database record is updated correctly, without However, if I pass an entity with only three or two fields set (ex: field1 and field3 with their new values) the record is not updated.
Should I get the entity of BD
and compare field by field if it is different and update it and then do the update?