I have some parent records already inserted into the database. Now I want to add some child entries. To do this, I have completed the following steps:
- Get Parent Entries (A)
- Create a new baby record (B)
- Add a parent entry to the Navigation Child property. BA = A
- Call SaveChanges.
The problem is when I do this EF, inserts a new parent, and then adds the child with a foreign key pointing to the new newly inserted parent, instead of only inserting the child with the mapping into the already existing parent. I also checked the parent primary key while saving the child, and it exists in the database.
Please note that I am using the database identifier for the parent and child. One thing I noticed is adding / Save the parent and child from the same context object, then it works fine.
You need to fix it as soon as possible. Any help would be greatly appreciated.
source share