0

我有这个代码保存一个简单的实体:

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]

在谷歌搜索后,我发现收到此错误的模式人有关系问题,这不是我的情况

谢谢

4

1 回答 1

2

Maybe the answer here can help you: It has a DefiningQuery but no InsertFunction element... err

It could be that in the EF model it is configured that this entity is a view and not a table. Views don't support create, update or delete operations, so you can't insert.

于 2011-09-17T19:13:50.393 回答