User-707554951 posted
Hi CrazyOldPotato.
From your description and code, you want to add c1 to c table in database, if that the case. According the relationship between you class(a,b,c). I suggest you could following the steps:
Using the following code to add a1 to database:
using (Model2 context = new Model2())
{
a a1 = new a { id = 1 };
context.a.Add(a1);
context.SaveChanges();
}
Then add b1 to database:
using (Model2 context = new Model2())
{
a a1 = context.a.Find(1);
b b1 = new b { id = 1, a_ID = a1 };
context.b.Add(b1);
context.SaveChanges();
}
Finally, you could add c1 to database without any error:
using (Model2 context=new Model2())
{
b b1 = context.b.Find(1);
c c1 = new c { b_id = b1 };
context.c.Add(c1);
context.Entry(c1.b_id).State = EntityState.Unchanged;
// context.Entry(c1.b_id.a_ID).State = EntityState.Unchanged; This is not required for us.
context.SaveChanges();
}
For I couldn't restored your problem. If you still have problem about this, would you please provide detailed error message for us. So that we could solve your problem timely.
Best regards
Cathy