0
我想記錄的全部信息複製到另一個在EF C#:從現有的對象實體框架對象C#
List<Cohort> AnYearsCohorts = oDB.Cohorts.Where(x=>x.Year == oCh.Year).ToList();
foreach (Cohort ochort in AnYearsCohorts)
{
Cohort nChort = new Cohort();
nChort = ochort;
nChort.Year = Year;
nChort.ID = 0;
oDB.Cohorts.Add(nChort);
}
oDB.SaveChanges();
但得到了以下錯誤:
{"The property 'ID' is part of the object's key information and cannot be modified. "}
只是刪除此行:nChort.ID = 0; – jpgrassi