示例#1
0
        private void RecursiveDelete(string key, TransactionInformation transactionInformation)
        {
            var document = Database.Documents.Get(key, transactionInformation);

            if (document == null)
            {
                return;
            }

            var documentsToDelete = document.Metadata.Value <RavenJArray>(MetadataKeys.DocumentsToCascadeDelete);

            if (documentsToDelete != null)
            {
                foreach (var documentToDelete in documentsToDelete)
                {
                    var documentId = documentToDelete.Value <string>();
                    if (!CascadeDeleteContext.HasAlreadyDeletedDocument(documentId))
                    {
                        CascadeDeleteContext.AddDeletedDocument(documentId);
                        RecursiveDelete(documentId, transactionInformation);
                        Database.Documents.Delete(documentId, null, transactionInformation);
                    }
                }
            }
            var attachmentsToDelete = document.Metadata.Value <RavenJArray>(MetadataKeys.AttachmentsToCascadeDelete);

            if (attachmentsToDelete != null)
            {
                foreach (var attachmentToDelete in attachmentsToDelete)
                {
                    Database.Attachments.DeleteStatic(attachmentToDelete.Value <string>(), null);
                }
            }
            return;
        }
示例#2
0
        private void RecursiveDelete(string key)
        {
            var document = Database.Documents.Get(key);

            if (document == null)
            {
                return;
            }

            var documentsToDelete = document.Metadata.Value <RavenJArray>(MetadataKeys.DocumentsToCascadeDelete);

            if (documentsToDelete != null)
            {
                foreach (var documentToDelete in documentsToDelete)
                {
                    var documentId = documentToDelete.Value <string>();
                    if (!CascadeDeleteContext.HasAlreadyDeletedDocument(documentId))
                    {
                        CascadeDeleteContext.AddDeletedDocument(documentId);
                        RecursiveDelete(documentId);
                        Database.Documents.Delete(documentId, null);
                    }
                }
            }

            return;
        }
        public override void OnDelete(string key, TransactionInformation transactionInformation)
        {
            if (CascadeDeleteContext.IsInCascadeDeleteContext)
            {
                return;
            }

            using (Database.DisableAllTriggersForCurrentThread())
                using (CascadeDeleteContext.Enter())
                {
                    var document = Database.Get(key, transactionInformation);
                    if (document == null)
                    {
                        return;
                    }


                    var documentsToDelete = document.Metadata.Value <RavenJArray>(MetadataKeys.DocumentsToCascadeDelete);

                    if (documentsToDelete != null)
                    {
                        foreach (var documentToDelete in documentsToDelete)
                        {
                            var documentId = documentToDelete.Value <string>();
                            if (!CascadeDeleteContext.HasAlreadyDeletedDocument(documentId))
                            {
                                CascadeDeleteContext.AddDeletedDocument(documentId);
                                Database.Delete(documentId, null, transactionInformation);
                            }
                        }
                    }

                    var attachmentsToDelete = document.Metadata.Value <RavenJArray>(MetadataKeys.AttachmentsToCascadeDelete);

                    if (attachmentsToDelete != null)
                    {
                        foreach (var attachmentToDelete in attachmentsToDelete)
                        {
                            Database.DeleteStatic(attachmentToDelete.Value <string>(), null);
                        }
                    }
                }
        }