It\'s quite self-explainatory. I have a class that contains another Let\'s call them Subject and Classroom
public class Subject
{
public Classroom Class {get;
Without seeing you're actual code on how you're either updating or creating your Subject
entity, it's hard to tell. However, you're probably not attaching the Classroom so EF is assuming that the entity is new, when it's really not.
using (Model m = new Model())
{
m.Subject.Add(subject);
m.Classrooms.Attach(subject.Class);
m.SaveChanges();
}
Even though the PK is the same, without attaching to the Context, EF has no way of figuring out what you're intention is. Attaching the entity explicitly tells your context what you want.