I have an entity model with (among others) following four entities:
QCompany: - PK_Company - CompanyName - QAddress - a collection of addresses
QAddress: - PK_Address - Streetname - QZipCode - QAddressType
QAddressType: - PK_AddressType - Description
QZipCode: - PK_ZipCode - ZipCode - Maildepot
I try to do the following:
I have an existing company that i want to add new addresses to.
QAddress addr = new QAddress { .... };
I use WCF so I have to send the new entityobject addr to the wcf-service. There I try to add the address to the context.
_context.AddToQAddress(addr); _context.SaveChanges();
Then I get an error: An object with the same key already exists in the ObjectStateManager.
So I try to attach the address
_context.Attach(addr);
But then i get the following error: Object entity key i null.....
My next move was to add the addresses to the company directly: QAddress[] addresses = new QAddresses {addr}; company.QAddress = addresses;
and attach the updated company to the context.
_context.Attach(company);
But the same errors occur every time.
I'm going crazy. I don't seem to find a way to solve this problem.
Can anyone help?