OnDelete Element (CSDL)
The OnDelete element in conceptual schema definition language (CSDL) defines behavior that is connected with an association. If the Action attribute is set to Cascade on one end of an association, related entity types on the other end of the association are deleted when the entity type on the first end is deleted. If the association between two entity types is a primary key-to-primary key relationship, then a loaded dependent object is deleted when the principal object on the other end of the association is deleted regardless of the OnDelete specification. For more information, see Defining and Managing Relationships. Only related entity types that have been loaded into the ObjectContext are deleted.
Note
The OnDelete element only affects the runtime behavior of an application; it does not affect behavior in the data source. The behavior defined in the data source should be the same as the behavior defined in the application.
An OnDelete element can have the following child elements (in the order listed):
Documentation (zero or one element)
Annotation elements (zero or more elements)
Applicable Attributes
The table below describes the attributes that can be applied to the OnDelete element.
Attribute Name | Is Required | Value |
---|---|---|
Action |
Yes |
Cascade or None . If Cascade , dependent entity types will be deleted when the principal entity type is deleted. If None , dependent entity types will not be deleted when the principal entity type is deleted. |
Note
Any number of annotation attributes (custom XML attributes) may be applied to the Association element. However, custom attributes may not belong to any XML namespace that is reserved for CSDL. The fully-qualified names for any two custom attributes cannot be the same.
Example
The following example shows an Association element that defines the CustomerOrders association. The OnDelete element indicates that all Orders that are related to a particular Customer and have been loaded into the ObjectContext will be deleted when the Customer is deleted.
<Association Name="CustomerOrders">
<End Type="ExampleModel.Customer" Role="Customer" Multiplicity="1">
<OnDelete Action="Cascade" />
</End>
<End Type="ExampleModel.Order" Role="Order" Multiplicity="*" />
</Association>
See Also
Concepts
Entity Framework Overview
CSDL Specification
Schema Element (CSDL)
Other Resources
CSDL, SSDL, and MSL Specifications
ADO.NET Entity Data Model Tools
Build Date:
2015-07-20