다음을 통해 공유


DeleteBehavior Enum

Definition

Indicates how a delete operation is applied to dependent entities in a relationship when the principal is deleted or the relationship is severed.

public enum DeleteBehavior
type DeleteBehavior = 
Public Enum DeleteBehavior
Inheritance
DeleteBehavior

Fields

Name Value Description
ClientSetNull 0

Sets foreign key values to null as appropriate when changes are made to tracked entities and creates a non-cascading foreign key constraint in the database. This is the default for optional relationships.

Restrict 1

Sets foreign key values to null as appropriate when changes are made to tracked entities and creates a non-cascading foreign key constraint in the database.

SetNull 2

Sets foreign key values to null as appropriate when changes are made to tracked entities and creates a foreign key constraint in the database that propagates null values from principals to dependents.

Cascade 3

Automatically deletes dependent entities when the principal is deleted or the relationship to the principal is severed, and creates a foreign key constraint in the database with cascading deletes enabled. This is the default for required relationships.

ClientCascade 4

Automatically deletes dependent entities when the principal is deleted or the relationship to the principal is severed, but creates a non-cascading foreign key constraint in the database.

NoAction 5

Sets foreign key values to null as appropriate when changes are made to tracked entities and creates a non-cascading foreign key constraint in the database.

ClientNoAction 6

Tracked dependents are not deleted and their foreign key values are not set to null when deleting principal entities. A non-cascading foreign key constraint is created in the database.

Remarks

Behaviors in the database are dependent on the database schema being created appropriately. The database is created appropriately when using Entity Framework Migrations or using one of https://learn.microsoft.com/dotnet/api/microsoft.entityframeworkcore.infrastructure.databasefacade.ensurecreated or https://learn.microsoft.com/dotnet/api/microsoft.entityframeworkcore.infrastructure.databasefacade.ensurecreatedasync .

See Cascade delete and deleting orphans in EF Core for more information and examples.

Applies to