Hi, I am starting to use Entity Framework in C# web project. but I got this error when run the code of context.SaveChanges().
"Unable to update the EntitySet 'FirstTables' because it has a DefiningQuery and no <UpdateFunction> element exists in the <MofificationFunctionMapping> element to support the current operation"
This is my codes:
....
var context = new MyEntiites();
var newTrans = context.FirstTables.First(c => c.ID ==1);
newTrans.InvoiceNo = "12345";
context.SaveChanges(); //here is the run time error above.
It is a SQL table, yes, I defined a primary key in it.
But I do not know if this is correct for my the property of the first column: in my table, the first Identity column is Identity key which set Indexable to Yes, and in Regular Data Space Specification (Filegroup or Partition SChema Name) set to PRIMARY.
in Text/Imagegroup: PRIMARY. Please let me know if this is correct to set my PRIMARY key in my table.
any other place I should Check? thanks
I checked how to set primary key, and just follows the steps: Right click the column and select "Set as Primary" key (I set the first Index column which is generated by SQL as primary key, and I can see the little Key image on that column and save it.
But I run the code, I still get the same error message.
The problem was in the table structure. To avoid the error we have to make one primary key in the table. After that, update the edmx. The problem will be fixed
Peter Cong
Member
527 Points
681 Posts
Run time error when using SaveChange() in entityFramework, help please!
Dec 13, 2012 01:13 PM|LINK
Hi, I am starting to use Entity Framework in C# web project. but I got this error when run the code of context.SaveChanges().
"Unable to update the EntitySet 'FirstTables' because it has a DefiningQuery and no <UpdateFunction> element exists in the <MofificationFunctionMapping> element to support the current operation"
This is my codes:
....
var context = new MyEntiites();
var newTrans = context.FirstTables.First(c => c.ID ==1);
newTrans.InvoiceNo = "12345";
context.SaveChanges(); //here is the run time error above.
Thanks for any help,
ignatandrei
All-Star
135087 Points
21669 Posts
Moderator
MVP
Re: Run time error when using SaveChange() in entityFramework, help please!
Dec 13, 2012 02:29 PM|LINK
Peter Cong
Member
527 Points
681 Posts
Re: Run time error when using SaveChange() in entityFramework, help please!
Dec 13, 2012 04:08 PM|LINK
It is a SQL table, yes, I defined a primary key in it.
But I do not know if this is correct for my the property of the first column: in my table, the first Identity column is Identity key which set Indexable to Yes, and in Regular Data Space Specification (Filegroup or Partition SChema Name) set to PRIMARY. in Text/Imagegroup: PRIMARY. Please let me know if this is correct to set my PRIMARY key in my table.
any other place I should Check? thanks
I checked how to set primary key, and just follows the steps: Right click the column and select "Set as Primary" key (I set the first Index column which is generated by SQL as primary key, and I can see the little Key image on that column and save it.
But I run the code, I still get the same error message.
Do I have to any extra steps, THanks
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Run time error when using SaveChange() in entityFramework, help please!
Dec 13, 2012 06:26 PM|LINK
Delete your .EDMX then re-generate it from database.
Weera
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Run time error when using SaveChange() in entityFramework, help please!
Dec 14, 2012 01:23 AM|LINK
Hi,
Is your column auto-generated? Or not allow duplicated values (I mean unique key)? Or something special set to that column by you?
RameshRajend...
Star
7983 Points
2099 Posts
Re: Run time error when using SaveChange() in entityFramework, help please!
Dec 14, 2012 02:00 AM|LINK
The problem was in the table structure. To avoid the error we have to make one primary key in the table. After that, update the edmx. The problem will be fixed