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

Throw if identifying foreign key is still unknown when saving changes #19405

Merged
merged 1 commit into from
Dec 30, 2019

Conversation

ajcvickers
Copy link
Member

Fixes #13666

Investigated this in more detail. Two Object (this is a custom Object class, not the normal System.Object type) entities are created. The first one is directly associated with a Container. The second one has no Container reference or FK set. However, because the FK is also part of the PK, and the PK uses generated values, it means that the FK gets a value set.

We do this to handle dependents encountered before principals when attaching the graph. But the intention here is that the dummy key value generated will be replaced once the principal is attached. If this doesn't happen, then SaveChanges will throw due to the FK constraint violation. This change provides clarity by failing in SaveChanges so we avoid ever sending the dummy value to the database.

Fixes #13666

Investigated this in more detail. Two `Object` (this is a custom `Object` class, not the normal `System.Object` type) entities are created. The first one is directly associated with a Container. The second one has no Container reference or FK set. However, because the FK is also part of the PK, and the PK uses generated values, it means that the FK gets a value set.

We do this to handle dependents encountered before principals when attaching the graph. But the intention here is that the dummy key value generated will be replaced once the principal is attached. If this doesn't happen, then SaveChanges will throw due to the FK constraint violation. This change provides clarity by failing in SaveChanges so we avoid ever sending the dummy value to the database.
@ajcvickers ajcvickers merged commit b5efa4b into master Dec 30, 2019
@ajcvickers ajcvickers deleted the LetsPushThingsSideways1225 branch December 30, 2019 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Propagate key values to the principal entity
2 participants