c# - Entity Framework resetting int values to 0 on inherited object -
i've been 4 hours trying find out i'm doing wrong tpt hierarchy, it's been big pain in neck.
i have base class:
public partial class registry { public int id_audit{get;set;} public string cud{get;set;} //key value public bool canceled{get;set;} public virtual icollection<articles> articles {get;set;} public virtual icollection<paid> paids {get;set;} //other base properties } public partial class sale : registry { public int idsale{get;set;} } public partial class cuote : registry { public int idcuote{get;set;} public int consec{get;set;} public int modification{get;set;} //other cuote properties }
at runtime interacts registry
object until it's decided object going be: sale
or cuote
, made extension class export base class derived class
public partial class registry { public sales tosale() { sale r = new sale { canceled = this.canceled, cud = this.cud, id_auditoria = this.id_auditoria, //other properties }; return r; } }
the same function made cuotes.
so use this
sale s = tempregistry.tosale(); dbcontext.registrys.add(s); dbcontext.savechanges();
but every time, savechanges()
throws exception:
the insert statement conflicted foreign key constraint "fk_registrys_audits". conflict occurred in database "testdb", table "dbo.audits", column 'id'. statement has been terminated.
but property set before savechanges()
executes, after savechanges()
not.
here's caption (names little bit different, id_auditoria == id_audit
, registros_auditoria == registry
):
on catch
my database schema this: can see there no more manipulation sale
object why it's keeping throwing me exception?
hi work, i'm not quite sure exact problem, forced rebuilt entity framework model, rename classes etc. , 1 of important change was
- deleted relationships between inherited objects: default navigation properties not deleted in previous model, apparently entityframework trying read
sale
.registry
instead of base class.
thank help.
Comments
Post a Comment