Exception on SaveChanges in Entity Framework

entity-framework savechanges

Question

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 google I found that mode people who got this error has a relation problems, this is not my case

Thanks

1
0
9/17/2011 6:50:20 PM

Accepted Answer

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.

2
5/23/2017 10:34:09 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow