Problem: when adding an object to "dbcontext", all nested order objects are "read" into the database, although nested objects are static data and only the shoudl link is added to the database.
Example: The database contains 0 orders and 3 items.
I add one order with two items.
Now the database contains 1 order and 5 items. Two items in order were βreadβ in the database, although the items had the correct primary keys before db.SaveChanges ().
I understand that I can attach existing elements to dbcontext before saving changes, but is this really the only way? Can EF find out that an element already exists when the primary key matches an existing element?
Does anyone know if this is different in the new version of EF CodeFirst?
source share