@@ -215,27 +215,24 @@ protected virtual async Task<ICollection> GetOrphansAsync(ICollection oldElement
215
215
public async Task IdentityRemoveAsync ( IList list , object obj , string entityName , ISessionImplementor session , CancellationToken cancellationToken )
216
216
{
217
217
cancellationToken . ThrowIfCancellationRequested ( ) ;
218
- if ( obj != null && await ( ForeignKeys . IsNotTransientSlowAsync ( entityName , obj , session , cancellationToken ) ) . ConfigureAwait ( false ) )
219
- {
220
- IType idType = session . Factory . GetEntityPersister ( entityName ) . IdentifierType ;
218
+ if ( obj == null || await ( ForeignKeys . IsTransientSlowAsync ( entityName , obj , session , cancellationToken ) ) . ConfigureAwait ( false ) )
219
+ return ;
221
220
222
- object idOfCurrent = await ( ForeignKeys . GetEntityIdentifierIfNotUnsavedAsync ( entityName , obj , session , cancellationToken ) ) . ConfigureAwait ( false ) ;
223
- List < object > toRemove = new List < object > ( list . Count ) ;
224
- foreach ( object current in list )
221
+ var persister = session . Factory . GetEntityPersister ( entityName ) ;
222
+ IType idType = persister . IdentifierType ;
223
+ object idToRemove = persister . GetIdentifier ( obj ) ;
224
+
225
+ for ( var index = list . Count - 1 ; index >= 0 ; index -- )
226
+ {
227
+ object current = list [ index ] ;
228
+ if ( current == null )
225
229
{
226
- if ( current == null )
227
- {
228
- continue ;
229
- }
230
- object idOfOld = await ( ForeignKeys . GetEntityIdentifierIfNotUnsavedAsync ( entityName , current , session , cancellationToken ) ) . ConfigureAwait ( false ) ;
231
- if ( idType . IsEqual ( idOfCurrent , idOfOld , session . Factory ) )
232
- {
233
- toRemove . Add ( current ) ;
234
- }
230
+ continue ;
235
231
}
236
- foreach ( object ro in toRemove )
232
+
233
+ if ( obj == current || idType . IsEqual ( idToRemove , persister . GetIdentifier ( current ) , session . Factory ) )
237
234
{
238
- list . Remove ( ro ) ;
235
+ list . RemoveAt ( index ) ;
239
236
}
240
237
}
241
238
}
0 commit comments