![]() ![]() ![]() The ClientSetNull is used when you have entities that may or may not have a parent, and you want EF to take care of nulling out the foreign key for you.It is the default option for entities that cannot exist without a parent usually make use of required relationships.The Cascade option is used when you have entities that cannot exist without a parent, and you want EF to take care of deleting the children automatically.It is not possible to save a null foreign key value, which results in the following effects. Required Relationships (non-nullable foreign key) It is possible to save a null foreign key value, which results in the following effects. Optional Relationships (nullable foreign key) The following example configures the relationship as required and specifies that dependant rows are deleted when the principal is deleted. Protected override void OnModelCreating(ModelBuilder modelBuilder) ![]() The following example set a foreign key field to null when the principal is deleted. Setting a foreign key value to null is not valid if the foreign key is not nullable. SetNull: The foreign key values in dependent rows should update to NULL.Cascade: Child/dependent entity should be deleted.The OnDelete method takes a DeleteBehavior enum as a parameter. In Entity Framework Core, the OnDelete Fluent API method is used to specify the delete behavior for a dependent entity when the principal is deleted.EF Core covers a closely related concept and implements several different delete behaviors and allows for the configuration of the delete behaviors of individual relationships.Cascade delete allows the deletion of a row to trigger the deletion of related rows automatically. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |