c# - EF 5 Code First, multiple parent child with cascade delete? -


i have following model:

public class parent1 {    public int id {get;set;}    public list<contact> contacts {get;set;} }  public class parent2 {    public int id {get;set;}    public list<contact> contacts {get;set;} }  public class parent3 {    public int id {get;set;}    public list<contact> contacts {get;set;} }  public class contact {    public int id {get;set;}    public parent1 parent1 {get;set;}    public parent2 parent2 {get;set;}    public parent3 parent3 {get;set;} } 

is possible have cascade deletion in scenario, 3 foreign keys on contact optional, possible enable in ef or there better way of achieving scenario?

thanks

if want delete contact object when parent object deleted, must configure parentside of association. this.

modelbuilder.entity<parententity>()     .hasmany(p => p.contact)     .withrequired()     .hasforeignkey(c => c.parententityid)     .willcascadeondelete(true);// turn off change false parameter. 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -