I’m using stubs to update my entities and when the updated entity consists of columns that have values changed from non-nulls to nulls, the nulls are not persisted to the database i.e. the record continues to hold the previous non-null values.
What am I doing wrong?
public void UpdateEntity(Entity e)
{
_context.Works.Attach(new Entity{ Id = e.Id });
_context.ApplyCurrentValues("Entities", e);
_context.SaveChanges();
}
The problem is that you need to assign
nullto these properties after youAttach(), not before. PerhapsApplyCurrentValues()only copies non-already-identical properties? (I’ve never tested, but it would be reasonable if it did.)