I have a Many To Many Relationship using a linking table which contains additional information. 3 Entities ,LHS, RHS, LHSRHS LHS 1 - * with LHSRHS RHS 1 - * with LHSRHS
I use the designer to generate EDMX based on the tables
I have 2 issues 1) If a create all 3 entities (new ones) link them up and try to persist i get a FK violation as it tries to insert into the LHSRHS tables before inserting into the RHS table
2) If I load a LHS object from the DB, then try to create a RHS object and link it to the LHS object i get a FK violation. If I load a RHS object from the DB, then try to create a LHS object and link it to the RHS object i works perfectly.
CODE for this :
//WORKS
eftestEntities es = new eftestEntities();
RHS existing = es.RHS.First();
LHS newObject = new LHS();
newObject.ID = "LHs1";
newObject.Name = "LHs1";
LHSRHS link = new LHSRHS();
link.Something = "some";
link.LHS = newObject;
existing.LHSRHS.Add(link);
es.SaveChanges();
...........
//DOES NOT WORK
eftestEntities es = new eftestEntities();
LHS existing = es.LHS.First();
RHS newObject = new RHS();
newObject.ID = "RHSNEW1";
newObject.Name = "RHSNEW";
LHSRHS link = new LHSRHS();
link.Something = "some";
link.RHS = newObject;
existing.LHSRHS.Add(link);
es.SaveChanges();
Anyone have any ideas ?