Share via


How to: Modify Deletion Behavior

When domain classes have domain relationships with each other, deleting one of the elements may cause related elements to be deleted also. For example, when a domain class is deleted, all the domain relationships for which the deleted element was a source or target are also deleted. This behavior is named delete propagation. You can customize delete propagation.

By default, the following rules govern delete propagation:

  • If an element is deleted, all elements embedded to it are also deleted. For example, if the Author and Publisher domain classes have embedding relationships with Book, and Book is deleted, then Author and Publisher are also deleted.

  • If an element is the source of embedding relationships, it is not deleted if its child is deleted. For example, if Bookis the parent of Author and Publisher, Book is not deleted if Author is deleted.

  • If a reference domain relationship is deleted, neither the source nor the target are deleted. For example, if Book has the reference relationship BookReferencesContent to Content, and the relationship is deleted, then neither Book nor Content is deleted.

Customizing Delete Propagation

The DSL Details window has a page named Delete Behavior. When you select a domain class and open this page, the relationships for which a given domain class is either a source or a target are listed, together with the Delete Style (either User specified or Track embeddings, which is the default). Whether deletion should be propagated is also listed. For example, if the Book domain class has an embedding relationship BookHasAuthors, then for Book, the BookHasAuthors relationship has the Propagate column selected by default. However, for Author, the BookHasAuthors relationship has the Propagate column cleared by default. This means that if Book is deleted, the deletion will be propagated and Author will also be deleted; if Author is deleted, the deletion will not be propagated and Book will not be deleted.

You can modify deletion behavior by changing the value of the Propagate column. You can also customize it by overriding the ShouldVisitRelationship and ShouldVisitRolePlayer methods in the ModelNameDeleteClosure class. You can see this class in the DomainModel.cs file under DomainModel.tt in the GeneratedCode folder of the Dsl project in a Domain-Specific Language Tools solution.

To modify the deletion behavior of a domain class

  1. In the DSL Explorer, select a domain class.

    The DSL Details window appears with the Delete Behavior page open.

  2. In the Delete Style column, change the value to User specified if you want to use custom code.

  3. Select Propagate to propagate the deletion.

See Also

Other Resources

Domain-Specific Language Tools Glossary

Change History

Date

History

Reason

July 2008

Rewrote and refactored project.

Content bug fix.