我有这个代码保存一个简单的实体:
ExecutionEngineEntities db = new ExecutionEngineEntities();
Task task = new Task();
task.Message = "Test";
task.Result = "Test";
task.Name = "Test";
db.Tasks.AddObject(task);
db.SaveChanges();
这是例外:
A first chance exception of type 'System.Data.UpdateException' occurred in System.Data.Entity.dll
Unable to update the EntitySet 'Tasks' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
The program '[6092] WebDev.WebServer40.EXE: Managed (v4.0.30319)' has exited with code 0 (0x0).
创建表的代码:
CREATE TABLE [dbo].[Tasks](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nchar](50) NULL,
[Message] [nchar](1000) NULL,
[Result] [nchar](1000) NULL
) ON [PRIMARY]
在谷歌搜索后,我发现得到此错误的模式人有关系问题,这不是我的情况
谢谢
也许这里的答案可以帮助您:它有一个DefiningQuery,但没有InsertFunction元素…犯错
可能在EF模型中,它被配置为该实体是视图而不是表。视图不支持创建、更新和删除操作,因此不能插入。