0

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

SexyMF
  • 10,657
  • 33
  • 102
  • 206

1 Answers1

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.

Community
  • 1
  • 1
Andreas
  • 6,447
  • 2
  • 34
  • 46
  • Thanks, the answer helped me, but I have created a table not a view.... What went wrong, how do i make EF to see it as an table and not a view? – SexyMF Sep 17 '11 at 19:20
  • In the answer that I have linked there is another link: http://blogs.msdn.com/b/alexj/archive/2009/09/01/tip-34-how-to-work-with-updatable-views.aspx which tells you how to check if it's configured as a table or a view in the model – Andreas Sep 17 '11 at 19:24