我有这个代码保存一个简单的实体:
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]
在谷歌搜索后我发现模式中出现此错误的人有关系问题,这不是我的情况
由于
答案 0 :(得分:2)
也许这里的答案可以帮到你:It has a DefiningQuery but no InsertFunction element... err
可能是在EF模型中,它被配置为该实体是视图而不是表。视图不支持创建,更新或删除操作,因此无法插入。