Reputation: 2546
i have two table parent(id p_key,name)
and child(addresid,city, id ForeignKey)
table have one to many relationship ,
so if i am deleting any recording from parent table then all related record should be deleted from child table
i am using entity framework code first approach
Upvotes: 1
Views: 1566
Reputation: 39966
Add this to your DB Context
:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<parent>()
.HasOptional(c => c.child)
.WithOptionalDependent()
.WillCascadeOnDelete(true);
}
Have a look at this:Enabling Cascade Delete
Upvotes: 2