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

Sidecars 7, Brazil 0... #401

Merged
merged 1 commit into from
Jul 9, 2014
Merged

Sidecars 7, Brazil 0... #401

merged 1 commit into from
Jul 9, 2014

Conversation

ajcvickers
Copy link
Member

Sidecars 7, Brazil 0... (Propagate generated principal values to FKs on SaveChanges)

Some primary/principal key values are generated in the store when the entity is saved--for example, for Identity columns. These values are written back into the state entry by the update pipeline. Foreign keys that reference these principal key values also need to be updated with the generated values so that the entire graph stays in sync and so that subsequent commands issued by the update pipeline make use of the newly generated values. Also, if the save transaction is not committed, then these generated values should be discarded.

Values written into the state manager by the update pipeline are placed in a temporary transparent sidecar so that they can be discarded later. When a change is detected (or notification is made) that a principal property has changed, then the state manager now finds dependents and updates FK values appropriately. These are also written into the transparent sidecar so that the update pipeline can read them like normal values for subsequent commands, but the values can still be discarded if SaveChanges fails.

Still working on some tests.


// TODO: Perf: make it faster to check if the property is at the principal end or not
var foreignKeys = _configuration.Model.EntityTypes.SelectMany(
e => e.ForeignKeys.Where(f => f.ReferencedProperties.Contains(property))).ToArray();
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding this as an overload of IModel.GetReferencingForeignKeys()

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

@AndriySvyryd
Copy link
Member

:shipit: Assuming no major changes are required because of my feedback.

@@ -201,10 +240,10 @@ private void InitialFixup(StateEntry entry, EntityState oldState)
}

// Handle case where the new entity is the principal
foreach (var foreignKey in _stateManager.Model.EntityTypes.SelectMany(
foreach (var foreignKey in stateManager.Model.EntityTypes.SelectMany(
e => e.ForeignKeys.Where(f => f.ReferencedEntityType == entityType)))
Copy link
Member

Choose a reason for hiding this comment

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

Use stateManager.Model.GetReferencingForeignKeys(entityType)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

…on SaveChanges)

Some primary/principal key values are generated in the store when the entity is saved--for example, for Identity columns. These values are written back into the state entry by the update pipeline. Foreign keys that reference these principal key values also need to be updated with the generated values so that the entire graph stays in sync and so that subsequent commands issued by the update pipeline make use of the newly generated values. Also, if the save transaction is not committed, then these generated values should be discarded.

Values written into the state manager by the update pipeline are placed in a temporary transparent sidecar so that they can be discarded later. When a change is detected (or notification is made) that a principal property has changed, then the state manager now finds dependents and updates FK values appropriately. These are also written into the transparent sidecar so that the update pipeline can read them like normal values for subsequent commands, but the values can still be discarded if SaveChanges fails.

Still working on some tests.
@ajcvickers ajcvickers merged commit 5168a4d into dev Jul 9, 2014
@ajcvickers ajcvickers deleted the FkProp703 branch July 9, 2014 22:27
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.

2 participants