Edit This seems to occur for any Entity property that references another entity in one direction. In other words, for the below example, the fact
A way to make it work is using the property API:
var foo = context.Foos.Find(1);
context.Entry(foo).Reference(f => f.Bar).CurrentValue = null;
context.SaveChanges();
The benefit is that this works without loading the foo.Bar
by lazy loading and it also works for pure POCOs that don't support lazy loading or change tracking proxies (no virtual
properties). The downside is that you need a context
instance available at the place where you want to set the related Bar
to null
.