有许多表,其中每个表中都有GUID作为主键.我想从所有表中的原始记录创建一个具有新Guid的副本.
执行此操作时,我收到一个错误属性Guid是对象键信息的一部分,无法修改第#9行.
1. var project = context.Projects.FirstOrDefault(x => x.Guid == projectGuid); // existing record
2. if (project != null)
3. {
4. project.Guid = Guid.NewGuid(); // Setting newguid
5. //....... need same values from rest of the columns
6.
7. project.CreatedBy = userAccountGuid;
8. project.CreatedDate = DateTime.Now;
9. context.Projects.Add(project); // Adding a new record
10.
11. }