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