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

Store temporary values in the state entry #14256

Merged
merged 1 commit into from
Dec 29, 2018
Merged

Conversation

ajcvickers
Copy link
Member

Fixes #12378, #10167

The main breaking change here is that application logic that relies on the temporary value being set into the actual entity instance will be broken. Possibly the only place this is used is to trigger fixup between Added entities (before they are saved) using FK values only. This is pretty uncommon. The case where both navigation properties and FKs are excessively set will still work because the navigations will cause fixup to happen. Anyone hitting this can still make it work by grabbing temporary values from the state manager--tests that were hitting this have been updated to work this way.

Functionally, the change works like this:

  • If a property is set to a non-default value, then it cannot be temporary or store-generated
    • This is kind of a new restriction, but functionally shouldn't change anything that worked before
  • If a property has a default value, then it can have a temporary value set, which is stored in a new "sidecar".
  • When the update pipeline sets a store-generated value, it uses the same mechanism.
    • So, real values hide store generated values, which hide temporary values.
    • This means that if SaveChanges fails and the store-generated values are discarded, then the temporary values take over again.

Setting a store-generated or temporary value has been made explicit. Transparently setting store-generated values wasn't actually very useful.

@ajcvickers ajcvickers force-pushed the ReturnOfTheRucksack1226 branch 2 times, most recently from 96bf182 to ce13254 Compare December 29, 2018 00:05
@ajcvickers
Copy link
Member Author

@AndriySvyryd New version up and passed checks.

Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

foreach (var foreignKey in currentProperty
.DeclaringEntityType
.GetDerivedTypesInclusive()
.SelectMany(e => e.GetForeignKeys()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call GetDeclaredForeignKeys() to avoid duplicates

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even better currentProperty.GetContainingForeignKeys()

Fixes #12378, #10167

The main breaking change here is that application logic that relies on the temporary value being set into the actual entity instance will be broken. Possibly the only place this is used is to trigger fixup between Added entities (before they are saved) using FK values only. This is pretty uncommon. The case where both navigation properties and FKs are excessively set will still work because the navigations will cause fixup to happen. Anyone hitting this can still make it work by grabbing temporary values from the state manager--tests that were hitting this have been updated to work this way.

Functionally, the change works like this:
* If a property is set to a non-default value, then it cannot be temporary or store-generated
  * This is kind of a new restriction, but functionally shouldn't change anything that worked before
* If a property has a default value, then it can have a temporary value set, which is stored in a new "sidecar".
* When the update pipeline sets a store-generated value, it uses the same mechanism.
  * So, real values hide store generated values, which hide temporary values.
  * This means that if SaveChanges fails and the store-generated values are discarded, then the temporary values take over again.

Setting a store-generated or temporary value has been made explicit. Transparently setting store-generated values wasn't actually very useful.
@ajcvickers ajcvickers merged commit fc0bb3b into master Dec 29, 2018
@smitpatel smitpatel deleted the ReturnOfTheRucksack1226 branch January 10, 2019 03:30
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.

Store temporary key values in state entry rather than setting them on entity instances
2 participants