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

            if (pc.WasInitialized)
            {
                CollectionEntry ce = eventSource.PersistenceContext.GetCollectionEntry(pc);
                orphans = ce == null ? CollectionHelper.EmptyCollection : ce.GetOrphans(entityName, pc);
            }
            else
            {
                orphans = pc.GetQueuedOrphans(entityName);
            }

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

                    eventSource.Delete(entityName, orphan, false, null);
                }
            }
        }
Пример #2
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 : ce.GetOrphans(entityName, pc);
            }
            else
            {
                orphans = pc.GetQueuedOrphans(entityName);
            }

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

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