[英]Getting error while inserting the data into table "Unable to update the EntitySet "
I am trying to save the data in the database.我正在尝试将数据保存在数据库中。 Table name is product_color
.表名是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();
}
This is the function code to insert the data into table.这是将数据插入表的函数代码。
when db.SaveChanges();
当db.SaveChanges();
is called the below error shows:被称为以下错误显示:
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.
This usually happens when you have not defined any primary key on your table.这通常发生在您尚未在表上定义任何主键时。 When a table doesn't have a PK then the Entity Framework considers it to be a View and not a table and hence it doesn't allow data to be directly inserted to it.当表没有 PK 时,实体框架会将其视为视图而不是表,因此它不允许将数据直接插入其中。
Simply set a Primary Key on the table.只需在表上设置一个主键。 That should do the trick这应该够了吧
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.