【问题标题】:Getting error while inserting the data into table "Unable to update the EntitySet "将数据插入表“无法更新实体集”时出错
【发布时间】:2016-09-28 23:35:19
【问题描述】:

我正在尝试将数据保存在数据库中。表名是product_color

public void PostAddColour1()
{
     product_color pc = new product_color();
     pc.id = 999;
     pc.product_id=2;
     pc.color_id=1;
     pc.display_order=3;
     db.product_color.Add(pc);
     db.SaveChanges();
}

这是向表中插入数据的函数代码。

db.SaveChanges(); 被调用时,会出现以下错误:

Unable to update the EntitySet 'product_color' because it has a
DefiningQuery and no <InsertFunction> element exists in the 
ModificationFunctionMapping> element to support the current operation.

【问题讨论】:

标签: c# entity-framework


【解决方案1】:

这通常发生在您没有在表上定义任何主键时。当一个表没有 PK 时,实体框架认为它是一个 View 并且 不是一个表,因此它不允许将数据直接插入到它。

只需在桌子上设置一个主键。这应该可以解决问题

你可以在here阅读更多内容

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多