@@ -38,7 +38,7 @@ public ChangeDetector(
3838 /// any release. You should only use it directly in your code with extreme caution and knowing that
3939 /// doing so can result in application failures when updating to a new Entity Framework Core release.
4040 /// </summary>
41- public virtual void PropertyChanged ( InternalEntityEntry entry , IPropertyBase propertyBase , bool setModified )
41+ public virtual void PropertyChanged ( IInternalEntry entry , IPropertyBase propertyBase , bool setModified )
4242 {
4343 if ( entry . EntityState == EntityState . Detached
4444 || propertyBase is IServiceProperty )
@@ -62,16 +62,16 @@ public virtual void PropertyChanged(InternalEntityEntry entry, IPropertyBase pro
6262 else if ( propertyBase . GetRelationshipIndex ( ) != - 1
6363 && propertyBase is INavigationBase navigation )
6464 {
65- DetectNavigationChange ( entry , navigation ) ;
65+ DetectNavigationChange ( ( InternalEntityEntry ) entry , navigation ) ;
6666 }
6767 }
6868
69- private static void ThrowIfKeyChanged ( InternalEntityEntry entry , IProperty property )
69+ private static void ThrowIfKeyChanged ( IInternalEntry entry , IProperty property )
7070 {
7171 if ( property . IsKey ( )
7272 && property . GetAfterSaveBehavior ( ) == PropertySaveBehavior . Throw )
7373 {
74- throw new InvalidOperationException ( CoreStrings . KeyReadOnly ( property . Name , entry . EntityType . DisplayName ( ) ) ) ;
74+ throw new InvalidOperationException ( CoreStrings . KeyReadOnly ( property . Name , entry . StructuralType . DisplayName ( ) ) ) ;
7575 }
7676 }
7777
@@ -81,15 +81,15 @@ private static void ThrowIfKeyChanged(InternalEntityEntry entry, IProperty prope
8181 /// any release. You should only use it directly in your code with extreme caution and knowing that
8282 /// doing so can result in application failures when updating to a new Entity Framework Core release.
8383 /// </summary>
84- public virtual void PropertyChanging ( InternalEntityEntry entry , IPropertyBase propertyBase )
84+ public virtual void PropertyChanging ( IInternalEntry entry , IPropertyBase propertyBase )
8585 {
8686 if ( entry . EntityState == EntityState . Detached
8787 || propertyBase is IServiceProperty )
8888 {
8989 return ;
9090 }
9191
92- if ( ! entry . EntityType . UseEagerSnapshots ( ) )
92+ if ( ! entry . StructuralType . UseEagerSnapshots ( ) )
9393 {
9494 if ( propertyBase is IProperty asProperty
9595 && asProperty . GetOriginalValueIndex ( ) != - 1 )
@@ -99,7 +99,7 @@ public virtual void PropertyChanging(InternalEntityEntry entry, IPropertyBase pr
9999
100100 if ( propertyBase . GetRelationshipIndex ( ) != - 1 )
101101 {
102- entry . EnsureRelationshipSnapshot ( ) ;
102+ ( ( InternalEntityEntry ) entry ) . EnsureRelationshipSnapshot ( ) ;
103103 }
104104 }
105105 }
@@ -183,35 +183,27 @@ public virtual void DetectChanges(InternalEntityEntry entry)
183183 }
184184 }
185185
186- private bool DetectChanges ( InternalEntityEntry entry , HashSet < InternalEntityEntry > visited )
186+ private void DetectChanges ( InternalEntityEntry entry , HashSet < InternalEntityEntry > visited )
187187 {
188- var changesFound = false ;
189-
190- if ( entry . EntityState != EntityState . Detached )
188+ if ( entry . EntityState == EntityState . Detached )
191189 {
192- foreach ( var foreignKey in entry . EntityType . GetForeignKeys ( ) )
193- {
194- var principalEntry = entry . StateManager . FindPrincipal ( entry , foreignKey ) ;
195-
196- if ( principalEntry != null
197- && ! visited . Contains ( principalEntry ) )
198- {
199- visited . Add ( principalEntry ) ;
190+ return ;
191+ }
200192
201- if ( DetectChanges ( principalEntry , visited ) )
202- {
203- changesFound = true ;
204- }
205- }
206- }
193+ foreach ( var foreignKey in entry . EntityType . GetForeignKeys ( ) )
194+ {
195+ var principalEntry = entry . StateManager . FindPrincipal ( entry , foreignKey ) ;
207196
208- if ( LocalDetectChanges ( entry ) )
197+ if ( principalEntry != null
198+ && ! visited . Contains ( principalEntry ) )
209199 {
210- changesFound = true ;
200+ visited . Add ( principalEntry ) ;
201+
202+ DetectChanges ( principalEntry , visited ) ;
211203 }
212204 }
213205
214- return changesFound ;
206+ LocalDetectChanges ( entry ) ;
215207 }
216208
217209 private bool LocalDetectChanges ( InternalEntityEntry entry )
@@ -274,7 +266,7 @@ private bool LocalDetectChanges(InternalEntityEntry entry)
274266 /// any release. You should only use it directly in your code with extreme caution and knowing that
275267 /// doing so can result in application failures when updating to a new Entity Framework Core release.
276268 /// </summary>
277- public bool DetectValueChange ( InternalEntityEntry entry , IProperty property )
269+ public bool DetectValueChange ( IInternalEntry entry , IProperty property )
278270 {
279271 var current = entry [ property ] ;
280272 var original = entry . GetOriginalValue ( property ) ;
@@ -296,26 +288,33 @@ public bool DetectValueChange(InternalEntityEntry entry, IProperty property)
296288 return false ;
297289 }
298290
299- private void LogChangeDetected ( InternalEntityEntry entry , IProperty property , object ? original , object ? current )
291+ private void LogChangeDetected ( IInternalEntry entry , IProperty property , object ? original , object ? current )
300292 {
301293 if ( _loggingOptions . IsSensitiveDataLoggingEnabled )
302294 {
303- _logger . PropertyChangeDetectedSensitive ( entry , property , original , current ) ;
295+ if ( entry is InternalEntityEntry entityEntry )
296+ {
297+ _logger . PropertyChangeDetectedSensitive ( entityEntry , property , original , current ) ;
298+ }
304299 }
305300 else
306301 {
307- _logger . PropertyChangeDetected ( entry , property , original , current ) ;
302+ if ( entry is InternalEntityEntry entityEntry )
303+ {
304+ _logger . PropertyChangeDetected ( entityEntry , property , original , current ) ;
305+ }
308306 }
309307 }
310308
311- private bool DetectKeyChange ( InternalEntityEntry entry , IProperty property )
309+ private bool DetectKeyChange ( IInternalEntry entry , IProperty property )
312310 {
313311 if ( property . GetRelationshipIndex ( ) < 0 )
314312 {
315313 return false ;
316314 }
317315
318- var snapshotValue = entry . GetRelationshipSnapshotValue ( property ) ;
316+ var entityEntry = ( InternalEntityEntry ) entry ;
317+ var snapshotValue = entityEntry . GetRelationshipSnapshotValue ( property ) ;
319318 var currentValue = entry [ property ] ;
320319
321320 var comparer = property . GetKeyValueComparer ( ) ;
@@ -326,19 +325,19 @@ private bool DetectKeyChange(InternalEntityEntry entry, IProperty property)
326325 {
327326 var keys = property . GetContainingKeys ( ) ;
328327 var foreignKeys = property . GetContainingForeignKeys ( )
329- . Where ( fk => fk . DeclaringEntityType . IsAssignableFrom ( entry . EntityType ) ) ;
328+ . Where ( fk => fk . DeclaringEntityType . IsAssignableFrom ( entityEntry . EntityType ) ) ;
330329
331330 if ( _loggingOptions . IsSensitiveDataLoggingEnabled )
332331 {
333- _logger . ForeignKeyChangeDetectedSensitive ( entry , property , snapshotValue , currentValue ) ;
332+ _logger . ForeignKeyChangeDetectedSensitive ( entityEntry , property , snapshotValue , currentValue ) ;
334333 }
335334 else
336335 {
337- _logger . ForeignKeyChangeDetected ( entry , property , snapshotValue , currentValue ) ;
336+ _logger . ForeignKeyChangeDetected ( entityEntry , property , snapshotValue , currentValue ) ;
338337 }
339338
340- entry . StateManager . InternalEntityEntryNotifier . KeyPropertyChanged (
341- entry , property , keys , foreignKeys , snapshotValue , currentValue ) ;
339+ entityEntry . StateManager . InternalEntityEntryNotifier . KeyPropertyChanged (
340+ entityEntry , property , keys , foreignKeys , snapshotValue , currentValue ) ;
342341
343342 return true ;
344343 }
@@ -487,7 +486,6 @@ public virtual void SetEvents(
487486 public virtual void OnDetectingEntityChanges ( InternalEntityEntry internalEntityEntry )
488487 {
489488 var @event = DetectingEntityChanges ;
490-
491489 if ( @event != null )
492490 {
493491 var changeTracker = internalEntityEntry . StateManager . Context . ChangeTracker ;
0 commit comments