I tried following code with following designed model.
First call to SaveChanges() is succeed but not when it comes to second call.
I have already worked 18 hours on this and can’t figure out what is the problem.
Specially when I can achieve the code goal manually with MSSQL server explorer !
Can anyone provide me a solution ?

var mc = new Model1Container1();
mc.Categories.Add(new Category() { Text = "Laptop" });
mc.Categories.Add(new Category() { Text = "TV" });
mc.SaveChanges();
var cat = mc.Categories.Where(c => c.Text == "Laptop").FirstOrDefault();
CKey ck = new CKey() { Key = "RAM" };
cat.CKeys.Add(ck);
for (int i = 1; i < 100; i++)
{
var ia = new Item() { Text = "MSI GX780-R", Category = cat };
ia.CProperties.Add(new CProperty() { Value = "4GB", CKey = ck });
mc.Items.Add(ia);
mc.SaveChanges();
}
You are trying to associate the same
CKeyinstance to 100 instances ofCProperty, but according to the graph of multiplicities, a given instance ofCKeycan only be associated to at most 1CProperty.Either create a new instance of
CKeyin each iteration of the loop, or modify your schema.