Entity framework 4 实体框架:插入新记录并更新此记录的信息

Entity framework 4 实体框架:插入新记录并更新此记录的信息,entity-framework-4,Entity Framework 4,我不知道如何处理这种情况,你能帮我吗 a我将新记录插入表中 var news = new News(); News.Title = "Hello World"; myRepository.InsertNews(catId,news); 在InsertNews()函数中,我调用myDbContext.SaveChanges();并将新记录插入到数据库中。在这段时间里,我已经有了新记录的Id news.Metadata = newData; b在我有了新记录的id之后,我需要调用其他函数来处

我不知道如何处理这种情况,你能帮我吗

a我将新记录插入表中

var news = new News();

News.Title = "Hello World";

myRepository.InsertNews(catId,news);
在InsertNews()函数中,我调用myDbContext.SaveChanges();并将新记录插入到数据库中。在这段时间里,我已经有了新记录的Id

news.Metadata = newData;
b在我有了新记录的id之后,我需要调用其他函数来处理一些业务并获取数据以更新新记录

news.Metadata = newData;
我调用myDbContext.SaveChanges()

我的系统显示一条错误消息。 属性“Id”是对象关键信息的一部分,无法修改。

请帮我解决这个问题。谢谢

看看这个帖子: