Click here to Skip to main content
15,038,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

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
phil.o 19-Oct-15 4:52am
What is the problem? Please describe the issue. And ask a formal question.
Member 10419297 19-Oct-15 8:43am
protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<childtable>().HasRequired(m => m.ParentTable).WithMany(m => m.ChildTable).WillCascadeOnDelete(true); //Line1

modelBuilder.Entity<childtable>().HasRequired(m => m.ParentTable).WithMany(m => m.ChildTable).HasForeignKey(m => m.EmailCampaignId).WillCascadeOnDelete(true);//Line2
for cascade delete which one i have to use Line1 or Line2 as per my understanding both are doing same thing. is there any difference between Line1 code and Line2 code

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900