public override async Task ExecuteAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); object id = Key; ISessionImplementor session = Session; ICollectionPersister persister = Persister; IPersistentCollection collection = Collection; bool affectedByFilters = persister.IsAffectedByEnabledFilters(session); bool statsEnabled = session.Factory.Statistics.IsStatisticsEnabled; Stopwatch stopwatch = null; if (statsEnabled) { stopwatch = Stopwatch.StartNew(); } await(PreUpdateAsync(cancellationToken)).ConfigureAwait(false); if (!collection.WasInitialized) { if (!collection.HasQueuedOperations) { throw new AssertionFailure("no queued adds"); } //do nothing - we only need to notify the cache... } else if (!affectedByFilters && collection.Empty) { if (!emptySnapshot) { await(persister.RemoveAsync(id, session, cancellationToken)).ConfigureAwait(false); } } else if (collection.NeedsRecreate(persister)) { if (affectedByFilters) { throw new HibernateException("cannot recreate collection while filter is enabled: " + MessageHelper.CollectionInfoString(persister, collection, id, session)); } if (!emptySnapshot) { await(persister.RemoveAsync(id, session, cancellationToken)).ConfigureAwait(false); } await(persister.RecreateAsync(collection, id, session, cancellationToken)).ConfigureAwait(false); } else { await(persister.DeleteRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false); await(persister.UpdateRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false); await(persister.InsertRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false); } Session.PersistenceContext.GetCollectionEntry(collection).AfterAction(collection); await(EvictAsync(cancellationToken)).ConfigureAwait(false); await(PostUpdateAsync(cancellationToken)).ConfigureAwait(false); if (statsEnabled) { stopwatch.Stop(); Session.Factory.StatisticsImplementor.UpdateCollection(Persister.Role, stopwatch.Elapsed); } }