Entity FrameWork - Exception on SaveChanges
I have this code saving a simple Entity:
ExecutionEngineEntities db = new ExecutionEngineEntities();
Task task = new Task();
task.Message = "Test";
task.Result = "Test";
task.Name = "Test";
db.Tasks.AddObject(task);
db.SaveChanges();
This is the exception:
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).
This is the create table code:
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]
After searching in goog开发者_运维知识库le I found that mode people who got this error has a relation problems, this is not my case
Thanks
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.
精彩评论