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
As title describes, we are experiencing issues with updating Owned Entities following DDD in EF Core 2.0.
According to DDD approach, Value Objects have to be immutable and due to this, we are getting following exception when we try to change/update our Value Objects with a new one.
Exception:
"The instance of entity type 'License.DeviceCapacity#LicenseDeviceCapacity' cannot be tracked because another instance with the same key value for {'LicenseKey'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values."
Steps to reproduce
In order to better explain the issue, I am sharing the code sample with you.
P.S. In whole project, we are using LicenseDBContext Object as Singleton.
When we try to reproduce exact same scenario with EntityFramework 6.1.3, we do not encounter any problem and everything goes smoothly. The problem is only with Entity Framework Core 2.0.
As far as we are concerned, this is a bug on EF Core, and until this is fixed, could you be kind enough to help us by share with us any possible temporary workarounds?
Further technical details
EF Core version: Microsoft.EntityFrameworkCore 2.0.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 2.0.0
Operating system: Microsoft Windows 7 or higher
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered:
The same issue is in EF Core 2.1 with InMemory xunit test
You can not get from the context (in memory database) an entity, change something and update with the same context. You get the famous error: The instance of entity type '....' cannot be tracked because another instance with the same key value for...
Hello,
As title describes, we are experiencing issues with updating Owned Entities following DDD in EF Core 2.0.
According to DDD approach, Value Objects have to be immutable and due to this, we are getting following exception when we try to change/update our Value Objects with a new one.
Exception:
Steps to reproduce
In order to better explain the issue, I am sharing the code sample with you.
License Entity Object:
LicenseDeviceCapacity Value Object (owned entity - by license):
LicenseDBContext Object:
LicenseRepository which we use for CRUD operations on License Entity Object:
Lastly as an example, when we try to update License's DeviceCapacity with following code, we are getting aforementioned exception.
P.S. In whole project, we are using LicenseDBContext Object as Singleton.
When we try to reproduce exact same scenario with EntityFramework 6.1.3, we do not encounter any problem and everything goes smoothly. The problem is only with Entity Framework Core 2.0.
As far as we are concerned, this is a bug on EF Core, and until this is fixed, could you be kind enough to help us by share with us any possible temporary workarounds?
Further technical details
EF Core version: Microsoft.EntityFrameworkCore 2.0.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 2.0.0
Operating system: Microsoft Windows 7 or higher
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: