Пример #1
0
        /// <summary> Delete any entities that were removed from the collection</summary>
        private async Task DeleteOrphansAsync(string entityName, IPersistentCollection pc, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            //TODO: suck this logic into the collection!
            ICollection orphans;

            if (pc.WasInitialized)
            {
                CollectionEntry ce = eventSource.PersistenceContext.GetCollectionEntry(pc);
                orphans = ce == null ? CollectionHelper.EmptyCollection : await(ce.GetOrphansAsync(entityName, pc, cancellationToken)).ConfigureAwait(false);
            }
            else
            {
                orphans = await(pc.GetQueuedOrphansAsync(entityName, cancellationToken)).ConfigureAwait(false);
            }

            foreach (object orphan in orphans)
            {
                if (orphan != null)
                {
                    log.Info("deleting orphaned entity instance: " + entityName);

                    await(eventSource.DeleteAsync(entityName, orphan, false, null, cancellationToken)).ConfigureAwait(false);
                }
            }
        }