1- // Copyright (C) 2008-2020 Xtensive LLC.
1+ // Copyright (C) 2008-2022 Xtensive LLC.
22// This code is distributed under MIT license terms.
33// See the License.txt file in the project root for more information.
44// Created by: Dmitri Maximov
@@ -16,9 +16,9 @@ namespace Xtensive.Orm.Internals
1616 /// </summary>
1717 public sealed class EntityChangeRegistry : SessionBound
1818 {
19- private readonly HashSet < EntityState > @new = new HashSet < EntityState > ( ) ;
20- private readonly HashSet < EntityState > modified = new HashSet < EntityState > ( ) ;
21- private readonly HashSet < EntityState > removed = new HashSet < EntityState > ( ) ;
19+ private readonly HashSet < EntityState > @new = new ( ) ;
20+ private readonly HashSet < EntityState > modified = new ( ) ;
21+ private readonly HashSet < EntityState > removed = new ( ) ;
2222 private int count ;
2323
2424 /// <summary>
@@ -34,7 +34,8 @@ internal void Register(EntityState item)
3434 {
3535 // Remove-create sequences fix for Issue 690
3636 if ( item . PersistenceState == PersistenceState . New && removed . Contains ( item ) ) {
37- removed . Remove ( item ) ;
37+ EnsureChangesAreNotPersisting ( ) ;
38+ _ = removed . Remove ( item ) ;
3839 count -- ;
3940 if ( item . DifferentialTuple . Difference == null ) {
4041 item . SetPersistenceState ( PersistenceState . Synchronized ) ;
@@ -43,18 +44,22 @@ internal void Register(EntityState item)
4344 item . SetPersistenceState ( PersistenceState . Modified ) ;
4445 }
4546 else if ( item . PersistenceState == PersistenceState . Removed && @new . Contains ( item ) ) {
46- @new . Remove ( item ) ;
47+ EnsureChangesAreNotPersisting ( ) ;
48+ _ = @new . Remove ( item ) ;
4749 count -- ;
4850 return ;
4951 }
5052 else if ( item . PersistenceState == PersistenceState . Removed && modified . Contains ( item ) ) {
51- modified . Remove ( item ) ;
53+ EnsureChangesAreNotPersisting ( ) ;
54+ _ = modified . Remove ( item ) ;
5255 count -- ;
5356 }
5457
5558 var container = GetContainer ( item . PersistenceState ) ;
56- if ( container . Add ( item ) )
59+ EnsureChangesAreNotPersisting ( ) ;
60+ if ( container . Add ( item ) ) {
5761 count ++ ;
62+ }
5863 }
5964
6065 /// <summary>
0 commit comments