-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Conversation
|
||
// 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(); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
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))) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
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.