EF 6. Multiple added entities may have the same primary key. Error

asp.net c# entity-framework entity-framework-6

Popular Answer

Solution:

context.Recipes.AddOrUpdate(x => x.Id_Recipe,
                new Recipe() { Id_Recipe = 1, Id_User = 1, Id_Category_Main = 1, Name_Recipe = "zupa z kurek", Rate = 0, Level = "Łatwe", Date_Recipe = DateTime.Now, URL_Photo = "test", Time = 45, Number_Person = 4, Steps = 4, Instruction = "test" } );

Change with:

    context.Categories_Recipes.Add(new Category_Recipe() { Id_Recipe = 3, Id_Category = 3 });
    context.SaveChanges();
0
9/10/2017 4:53:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow