I have a Property table and another is Detail table. Where I am using disconnected approach where multiple properties are added and then when we click the save button it will save changes to the database. This approach of not saving for every property added is because user can delete from the list also.
Here’s what I am doing
foreach (Property P in Results)
{
if(P.PropertyId==0 && P.EntityState==EntityState.Added)
Repository.Properties.AddObject(P);
}
but when I try to save the data
public void Save()
{
Repository.SaveChanges();
}
it returns error
Unable to determine the principal end of the ‘database.FK_Details_Property’
relationship. Multiple added entities may have the same primary key.
I think its because every time I call AddObject its primary key is 0 and I don’t know what could solve this problem. Is this similar or sounds familiar to anyone who has encountered it?
Thanks in advance
1)You may want to check about a circular dependency. It may be between the two entities Save Product with detail entities or viceversa
Check here : http://social.msdn.microsoft.com/Forums/sk/adodotnetentityframework/thread/5ba666ff-0103-4a83-b4d0-743c16a99491
2)Be careful when you add Repository.Properties.AddObject(P); because in the code behind the P entity still has a reference to Detail table.
Make sure the detail related entity doesn’t already save the objects that are linked to it.
If the Detail object has 3 properties , when you save Detail you will also save the 3 properties.