private void DetectKeyChange(InternalEntityEntry entry, IProperty property, Sidecar snapshot) { if (!snapshot.HasValue(property)) { return; } var keys = property.FindContainingKeys().ToList(); var foreignKeys = property.FindContainingForeignKeys(entry.EntityType).ToList(); if (keys.Count > 0 || foreignKeys.Count > 0) { var snapshotValue = snapshot[property]; var currentValue = entry[property]; // Note that mutation of a byte[] key is not supported or detected, but two different instances // of byte[] with the same content must be detected as equal. if (!StructuralComparisons.StructuralEqualityComparer.Equals(currentValue, snapshotValue)) { var stateManager = entry.StateManager; if (foreignKeys.Count > 0) { stateManager.Notify.ForeignKeyPropertyChanged(entry, property, snapshotValue, currentValue); foreach (var foreignKey in foreignKeys) { stateManager.UpdateDependentMap(entry, snapshot.GetDependentKeyValue(foreignKey), foreignKey); } } if (keys.Count > 0) { foreach (var key in keys) { stateManager.UpdateIdentityMap(entry, snapshot.GetPrincipalKeyValue(key), key); } stateManager.Notify.PrincipalKeyPropertyChanged(entry, property, snapshotValue, currentValue); } snapshot.TakeSnapshot(property); } } }
private void DetectKeyChange(InternalEntityEntry entry, IProperty property, Sidecar snapshot) { if (!snapshot.HasValue(property)) { return; } // TODO: Perf: make it fast to check if a property is part of any key var isPrimaryKey = property.IsPrimaryKey(); var isPrincipalKey = _model.GetReferencingForeignKeys(property).Any(); var isForeignKey = property.IsForeignKey(); if (isPrimaryKey || isPrincipalKey || isForeignKey) { var snapshotValue = snapshot[property]; var currentValue = entry[property]; // Note that mutation of a byte[] key is not supported or detected, but two different instances // of byte[] with the same content must be detected as equal. if (!StructuralComparisons.StructuralEqualityComparer.Equals(currentValue, snapshotValue)) { if (isForeignKey) { entry.StateManager.Notify.ForeignKeyPropertyChanged(entry, property, snapshotValue, currentValue); } if (isPrimaryKey) { entry.StateManager.UpdateIdentityMap(entry, snapshot.GetPrimaryKeyValue()); } if (isPrincipalKey) { entry.StateManager.Notify.PrincipalKeyPropertyChanged(entry, property, snapshotValue, currentValue); } snapshot.TakeSnapshot(property); } } }
private void DetectKeyChange(InternalEntityEntry entry, IProperty property, Sidecar snapshot) { if (!snapshot.HasValue(property)) { return; } var keys = property.FindContainingKeys().ToList(); var foreignKeys = property.FindContainingForeignKeys(entry.EntityType).ToList(); if (keys.Count > 0 || foreignKeys.Count > 0) { var snapshotValue = snapshot[property]; var currentValue = entry[property]; // Note that mutation of a byte[] key is not supported or detected, but two different instances // of byte[] with the same content must be detected as equal. if (!StructuralComparisons.StructuralEqualityComparer.Equals(currentValue, snapshotValue)) { var stateManager = entry.StateManager; if (foreignKeys.Count > 0) { stateManager.Notify.ForeignKeyPropertyChanged(entry, property, snapshotValue, currentValue); foreach (var foreignKey in foreignKeys) { stateManager.UpdateDependentMap(entry, snapshot.GetDependentKeyValue(foreignKey), foreignKey); } } if (keys.Count > 0) { foreach (var key in keys) { stateManager.UpdateIdentityMap(entry, snapshot.GetPrincipalKeyValue(key), key); } stateManager.Notify.PrincipalKeyPropertyChanged(entry, property, snapshotValue, currentValue); } snapshot.TakeSnapshot(property); } } }
private void DetectKeyChange(InternalEntityEntry entry, IProperty property, Sidecar snapshot) { if (!snapshot.HasValue(property)) { return; } // TODO: Perf: make it fast to check if a property is part of any key var isPrimaryKey = property.IsPrimaryKey(); var isPrincipalKey = _model.GetReferencingForeignKeys(property).Any(); var isForeignKey = property.IsForeignKey(); if (isPrimaryKey || isPrincipalKey || isForeignKey) { var snapshotValue = snapshot[property]; var currentValue = entry[property]; // Note that mutation of a byte[] key is not supported or detected, but two different instances // of byte[] with the same content must be detected as equal. if (!StructuralComparisons.StructuralEqualityComparer.Equals(currentValue, snapshotValue)) { if (isForeignKey) { entry.StateManager.Notify.ForeignKeyPropertyChanged(entry, property, snapshotValue, currentValue); } if (isPrimaryKey) { entry.StateManager.UpdateIdentityMap(entry, snapshot.GetPrimaryKeyValue()); } if (isPrincipalKey) { entry.StateManager.Notify.PrincipalKeyPropertyChanged(entry, property, snapshotValue, currentValue); } snapshot.TakeSnapshot(property); } } }