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

Cascade 3

For entities being tracked by the context, dependent entities will be deleted when the related principal is deleted.

ClientCascade 4

For entities being tracked by the context, dependent entities will be deleted when the related principal is deleted.

ClientNoAction 6

Note: it is unusual to use this value. Consider using ClientSetNull instead to match the behavior of EF6 with cascading deletes disabled.

ClientSetNull 0

For entities being tracked by the context, the values of foreign key properties in dependent entities are set to null when the related principal is deleted. This helps keep the graph of entities in a consistent state while they are being tracked, such that a fully consistent graph can then be written to the database. If a property cannot be set to null because it is not a nullable type, then an exception will be thrown when SaveChanges() is called.

NoAction 5

For entities being tracked by the context, the values of foreign key properties in dependent entities are set to null when the related principal is deleted. This helps keep the graph of entities in a consistent state while they are being tracked, such that a fully consistent graph can then be written to the database. If a property cannot be set to null because it is not a nullable type, then an exception will be thrown when SaveChanges() is called.

Restrict 1

For entities being tracked by the context, the values of foreign key properties in dependent entities are set to null when the related principal is deleted. This helps keep the graph of entities in a consistent state while they are being tracked, such that a fully consistent graph can then be written to the database. If a property cannot be set to null because it is not a nullable type, then an exception will be thrown when SaveChanges() is called.

SetNull 2

For entities being tracked by the context, the values of foreign key properties in dependent entities are set to null when the related principal is deleted. This helps keep the graph of entities in a consistent state while they are being tracked, such that a fully consistent graph can then be written to the database. If a property cannot be set to null because it is not a nullable type, then an exception will be thrown when SaveChanges() is called.

Remarks

Behaviors in the database are dependent on the database schema being created appropriately. Using Entity Framework Migrations or EnsureCreated() will create the appropriate schema.

Note that the in-memory behavior for entities that are currently tracked by the context can be different from the behavior that happens in the database.

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

Applies to