You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say we have Entity "A" with the children Entity "A1".
I want load "A" & "A1" in a context which i close right after.
After a while i have replaced the list with another "A1" (new object, same primary key), now when opening a new context trying to update "A" we run into an exception:
Exception message:
System.InvalidOperationException: 'The instance of entity type 'TransportProject' cannot be tracked because another instance of this type with the same key is already being tracked. When adding new entities, for most key types a unique temporary key value will be created if no key is set (i.e. if the key property is assigned the default value for its type). If you are explicitly setting key values for new entities, ensure they do not collide with existing entities or temporary values generated for other new entities. When attaching existing entities, ensure that only one entity instance with a given key value is attached to the context.'
Wouldn't it be helpful not to have to do all the work ourselves (as described in the link at the top) but rather trust the framework does this automatically?
Any reasons why it has been decided to implement it this way? Are there any plans or is there a chance this improvement will be implemented?
Thanks!
Further technical details
EF Core version: 1.1.0
Database Provider: SqLite
Operating system: Windows 10 Mobile
IDE: Visual Studio 2017 RC
The text was updated successfully, but these errors were encountered:
@groege We have attempted to do such things automatically in the past and found it fraught with problems, especially when it comes to graphs of entities where the relationships are different in different graphs. Also, when people are not expecting this behavior it can become very difficult to figure out what is happening--for example, I asked the context to track this object, but actually it just updated a different object and the first object is still not being tracked. All that being said, having a higher-level solution to this kind of issue is on our backlog--see #5536.
For now, if there are two object instances that represent the same entity, then it is the application's responsibility to know when this is happening and apply changes from one object to the other as appropriate. For example, if the context is already tracking one object, then changes made to another object with the same identity can be applied using something like this:
It's about the problem solved with this stackoverflow post:
http://stackoverflow.com/questions/7968598/entity-4-1-updating-an-existing-parent-entity-with-new-child-entities/7969372#7969372
Let's say we have Entity "A" with the children Entity "A1".
I want load "A" & "A1" in a context which i close right after.
After a while i have replaced the list with another "A1" (new object, same primary key), now when opening a new context trying to update "A" we run into an exception:
Wouldn't it be helpful not to have to do all the work ourselves (as described in the link at the top) but rather trust the framework does this automatically?
Any reasons why it has been decided to implement it this way? Are there any plans or is there a chance this improvement will be implemented?
Thanks!
Further technical details
EF Core version: 1.1.0
Database Provider: SqLite
Operating system: Windows 10 Mobile
IDE: Visual Studio 2017 RC
The text was updated successfully, but these errors were encountered: