Click here to Skip to main content
15,944,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have lately updated from EF4.3.1 (self tracking) to EF6.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 EF4 I had to null all navigations 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:
1. I have a parent entity node, say Person, that has been modified;
2. it contains more than one child entity nodes 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 EF 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 EF 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?
Updated 20-Jan-15 2:15am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900