Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex Object Type with Children (Single and List type Children) #20027

Closed
antoinecfmws opened this issue Feb 22, 2020 · 1 comment
Closed

Comments

@antoinecfmws
Copy link

We have an object with a complex type, to simplify it, let's consider a Blog with multiple Post. The Blog also has a userId that indicates who created the Blog.

When downloading a list of Blog we get a list of blogs, the posts associated to each Blog, the userId and the User object.

Note: The User can be the same for multiple Blogs, and the User object is a child of Blog.

The strategy is insert or update for now.

The issue we ran into, is that when we have multiple Blog entities, to Add or Update, the User may be the same for multiple blogs and hence the error:

The instance of entity type 'User' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.

Is it possible to tell Entity that the User object can be duplicated in other entities part of the same transaction?

Further technical details

EF Core version:
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: 3.1
Operating system: MacOS
IDE: VSCode

@ajcvickers
Copy link
Member

@antoinecfmws The problem is that resolving two instances of a single entity type into a single instance can get ambiguous and complicated fast. The application should resolve to a single instance before attaching the entities to the context.

See also #5536

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants