【问题标题】:Entity Framework: Insert a new record and Update information of this record实体框架:插入新记录并更新该记录的信息
【发布时间】:2011-04-12 05:51:09
【问题描述】:

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

一个。 我在表格中插入一条新记录

var news = new News();

News.Title = "Hello World";

myRepository.InsertNews(catId,news);

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

b. 获得新记录的 id 后,我需要调用其他函数来处理一些业务并取回数据以更新新记录。

news.Metadata = newData;

然后我调用 myDbContext.SaveChanges();

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

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

【问题讨论】:

    标签: entity-framework-4


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2023-01-28
    • 2021-09-21
    • 1970-01-01
    • 2016-08-09
    • 2017-08-07
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    相关资源
    最近更新 更多