This works as expected:
var customer = getCustomerFromSomewhere();
customer.Name = "Foo";
context.SaveChanges();
// ...
// ... in an override of SaveChanges, get the entry state
var isModified = entryState == EntityState.Modified; // ==true
The simple property was changed, so the entity is automatically marked as modified by the context.
Now consider a change to a navigation property which is a collection:
var customer = getCustomerFromSomewhere();
customer.Orders.Clear();
var order = getOrderFromSomewhere();
customer.Orders.Add(order);
context.SaveChanges();
// ...
// ... in an override of SaveChanges, get the entry state
var isModified = entryState == EntityState.Modified; // ==false
So the entity is not automatically marked as modified in this case. I get around this by manually marking it as modified, but I want it to occur automatically.
How do I do that? How do I detect whether an entity's relationships are modified?