I'm trying to update a record using EntityFramework 6 by attaching a disconnected entity. I want to update a single boolean field to false but it doesn't work. I have used sql server profiler and EF doesn't generate an update statement when calling SaveChanges on the context. But if i set the value to true, it works. Example:
This doesn't work:
private void UpdateUser()
{
var user = new User { ID = 5 };
this.Context.Users.Attach(user);
user.Locked = false;
this.Context.SaveChanges();
}
This works:
private void UpdateUser()
{
var user = new User { ID = 5 };
this.Context.Users.Attach(user);
user.Locked = true;
this.Context.SaveChanges();
}
I can fix by marking the property as modified like this:
this.Context.Entry(user).Property(e => e.Locked).IsModified = true;
But don't understand why does it work if the value is true and not if the value is false. There is a similar issue when trying to set a field to null.
There's probably something wrong with the entity data model or database but can't figure out what.