I have lately updated from EntityFramework
4.3.1 (with Self Tracking
) to EntityFramework
6.1.2 (without Detect Changes
). Due to having an MVC
client with complex entity tree views, and some other technological choices (like using SQL Server
's RowVersion
) I work in front of the database in detached mode. I have a new instance of the DbContext
with every request, and I mark the context's state for each entity.
It works just fine. Insert is working on the complete entity tree. Update is working on the type being handled. On EntityFramework
4 I had to null all navigation properties to have that flow working. Now I don't seem to have to do that.
BUT, I do get the above exception in the following scenario:
- I have a parent entity node, say Person, that has been modified;
- it contains more than one child entity node of the same type, say Phones, which are new entries, and thus their identity values are identical (0 for new);
Setting the state of the Person's entry to modified causes the exception, although I would expect EntityFramework
to not try to handle new (added) child entities' state. I can see when I have only one new phone under the modified Person, that the state of the Phone entry goes from detached to unchanged.
Do I need to do something so EntityFramework
knows to handle only the parent entity without its navigation properties on modifications? Or must I resolve to nulling all navigations as I did before?