Last post Sep 15, 2016 09:55 AM by sudip_inn
Sep 13, 2016 02:39 PM|sudip_inn|LINK
how to design class with parent child relation and how to set cascade delete option on as a result when i will remove data from parent then child data will be removed too?
discuss with small code example. thanks
Sep 15, 2016 05:16 AM|Deepak Panchal|LINK
Cascade delete allows dependent data to be automatically deleted when the principal record is deleted. If you delete a
Destination, for example, the related
Lodgings will also be deleted automatically. Entity Framework supports cascade delete behavior for in-memory data as well as in the database.
You can configure cascade delete on a relationship by using the WillCascadeOnDelete method. If a foreign key on the dependent entity is not nullable, then Code First sets cascade delete on the relationship. If a foreign key on the dependent entity is nullable,
Code First does not set cascade delete on the relationship, and when the principal is deleted the foreign key will be set to null.
.HasRequired(t => t.Department)
.WithMany(t => t.Courses)
.HasForeignKey(d => d.DepartmentID)
For more information please visit the link mentioned below.
Configuring Relationships with the Fluent API
Cascade Delete in Entity Framework Code-First:
Sep 15, 2016 09:55 AM|sudip_inn|LINK
1) what HasRequired does ?
2) what WithMany does ?
3) WillCascadeOnDelete set on parent table to child table ?