c# - Entityframework Code First and Generic Repository , lazy loading not working after insert -


i have defined (poco?) class in domain project :

public class employee {     public int id { get; set; }      public string name { get; set; }      public virtual icollection<contactofemployee> contactofemployees { get; set; } }  public class personel {     public int id { get; set; }      public string name { get; set; }      public virtual icollection<contactofpersonel> contactofpersonels { get; set; } }  public class contact {     public int id { get; set; }      public string name { get; set; }      public string tel { get; set; } }  public class contactofemployee : contact {     public int employeeid { get; set; }      public virtual personel employeecontact { get; set; } }  public class contactofpersonel : contact {     public int personelid { get; set; }      public virtual personel personelcontact { get; set; } }  public class databasecontext : dbcontext {     public dbset<employee> employees { get; set; }      public dbset<personel> personels { get; set; }      public dbset<contact> contacts { get; set; } } 

and have repository class crud operation ,i add use method , work perfect

 public virtual void add(t entity)  {        this.dbset.add(entity);  } 

but need use lazy loading after insert , savechange , use belong method :

    public virtual void add(t entity)     {         var myentity = this.dbset.create();         this.dbset.add(myentity);         this.context.entry(myentity).currentvalues.setvalues(entity);     } 

but field discriminator wrong save in database ,contact instead contactofemployee or contactofpersonel.

please me fix problem.

in add entity , lazy loading not working.and in tph dont creare proxy , use it.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -