die8292 die8292 - 7 months ago 21
SQL Question

Error "You have an error in your sql syntax entity framework" with Entity Framework

I get the "you have an error in your sql syntax entity framework" while trying to update the data in my MySQL database. I'm developing an MVC 4 ASP.NET application using a .edmx file to interact with the database.

This is my case: I have two tables: A and B. A has many B's and B has many A's so i made a C table with a foreign key to A and a foreign key to B. Now i'm trying to delete one of those rows in C. As i step on the

db.SaveChanges();
line, it throws me an exception that says what i already mentioned.

Does anybody know how can I fix it?

Answer

What happened is that at the moment of executing db.SaveChanges() (after an update), the .edmx tried to update the rows in the 'C' table, but as this table only had two foreign keys to A and B, the update operation wasn't supported. This is the solution that I found in other post in StackOverflow, and it worked for me:

  1. Right click on the edmx file, select Open with, XML editor
  2. Remove the DefiningQuery entirely
  3. Rename the store:Schema="dbo" to Schema="dbo (remove the "store:")
  4. Remove the store:Name=... property (entirely)

Note: this was moved from the question and posted on the OP's behalf.

Comments