Entity Framework - "An error occurred while updating records. For more information, see Internal Exception"

I have a problem, I just started studying EF Model First and Im staying at one point for some time. I got this error:

"An error occurred while updating records. See internal exception for more details."

I created a lightweight model in a diagram, generated a database, and wrote simple C # code to add only one row to the table, but the error appears constantly.

I am posting a screenshot with a Chart / Generated DLL / Simple Basic / And it throws an error

model and stuff

Link for larger size: http://i.imgur.com/bKGc4wv.png

+10
c # entity-framework ef-model-first
source share
9 answers

Turn Pluralization On . The problem is that you are modeling the object using the exclusive name convention ( Pupil ), while in your database you are using the plural Pupils names with s .

UPDATE

This post shows how you can turn it on or off. Some relevant excerpts from this post:

To turn the plural on or off

  • From the Tools menu, select Options.

  • In the Options dialog box, expand Database Tools. Note. Select Show all options if the database tool node is not displayed.

  • Click O / R Designer.

  • Set the Pluralization parameter for the names to Enabled = False so that the O / R constructor does not change the class names.

  • Set the Pluralization of Names option to Enabled = True to apply plural rules to object class names added to O / R Designer.

UPDATE 2

But keep in mind that you should avoid multiple names. You can read here how to do it (I will quote it here, in case the link does not work).

(...) When you work with the Entity Framework Code First approach, you create database tables from the classes of your model. Typically, the Entity Framework creates tables with multiple names. this means that if you have a model class PhoneNumber, the Entity platform will create a table for this class called PhoneNumbers. If you want to avoid a plural name and want to use a name like Customer, you can do it as follows In your DBContext class, override the OnModelCreating method as follows (...)

enter image description here

(...) Overriding this method will avoid creating tables with multiple names. Now it will create a table named "PhoneNumber", not "PhoneNumbers" (...)

+11
source share

this may be causing data to be converted from .net to sql. for example, a date and time conversion error.

this is not an exact mistake at all. you can see the exact error in watch at exception.InnerException.InnerException -> ResultView.

for me it was a null reference to a datetime column

+7
source share

For the records, I had this problem and was a stupid mistake at my end. My problem is related to data type mismatch. The data type in the database table and C # classes should be the same ......

+1
source share

I came across the same error:

"An error occurred while updating records. See internal exception for details."

Just Delete and create the * .edmx file . It worked for me. the error will disappear

0
source share

I have had this problem recently. This happened because user database permissions. check user database permissions, maybe the user does not have write permissions on db.

0
source share

I ran into the same problem and none of the above solutions helped me. In my Web Api 2 project, I actually updated my database and placed unique constraint on the SQL table column. . It really caused a problem. Just checking the values โ€‹โ€‹of the repeating columns before inserting helped me fix the problem!

0
source share

My problem was that the table id was not AUTO_INCREMENT, and I was trying to add a range.

0
source share

In my case .. the following steps are resolved:

There was a value for the column for which "Refresh" was set - replace it with "Edit" (not the sql keyword) There was a space in one of the column names (removed an extra space or cropping)

0
source share

I had the same problem with SaveChanges () in EF, but in my case I forget to update my sql table, after I used the migration, my problem is solved, so maybe updating your tables will solve the problem.

0
source share

All Articles