System.Data.Entity.Core.EntityCommandExecutionException MVC application uses EF

I am going to create an application form with a UUID as its unique key (and not the primary key).

I got an error:

An exception of type "System.Data.Entity.Core.EntityCommandExecutionException" occurred in EntityFramework.SqlServer.dll, but was not processed in the user code Additional information: An error occurred while executing the command definition. See Internal Exception for more details.

Database Connection String:

connectionString="Data Source=(localdb)\v11.0; Initial Catalog=FormsContext; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|Forms.mdf" providerName="System.Data.SqlClient" 

FormsContext.cs:

 namespace ApplicationForm.Models { public class FormsContext : DbContext { public FormsContext() : base("name=FormsContext") { } public System.Data.Entity.DbSet<ApplicationForm.Models.Form> Forms { get; set; } ... 

The database looks like this:

  FormsContext->Forms->{id,uuid,first,last...} 

I'm not sure what happened this time. Anyone help me get through this?

Edit / Resolution

I was not sure how to check the Inner Exception, and I did some research on this. So when I read the error message in the internal exception, I could solve my problem.

I found out what this error is. The query field is "firstname", but the column name of the table is "first". They did not match. As soon as I changed the name of the DB column, it worked again.

+7
source share
3 answers

found out what kind of error. The query field is 'firstname', but the column name of my table is 'first'. They did not match. As soon as I changed the name of the DB column, it worked again.

One must be diligent to keep everyone in sync if the database is constantly changing.

What for?

EF is just a set of mappings, a snapshot, and it doesn’t matter if these mappings are tables or stored procedures.

Any minor changes to column names or foreign key constraints can have ripple effects for any old mappings, and they must be reassigned / added to the new structure (s); otherwise, from here comes the strange behavior of old comparisons.

Sometimes these effects can create obvious errors like the ones you found, or even more insidious non-obvious logical errors that can provide subtle logical errors to running (compiled) software. I have seen logical errors from experience, and they happen.

Therefore, always be careful to synchronize EF displays.


I answered another EF question, but in the same vein.

I was faced with a situation where the stored procedures in the EF displayed at runtime failed because the internal change in the saved proc saw that the SQL cast section from the column name from the result and EF (displayed before the changed) failed. I have a screenshot in my answer that shows that EF / db changes can have a detrimental effect:

The data reader is incompatible. The member does not have a corresponding column in the data reader with the same name

+13
source

In my case, the following helped:

1) click the View Detail.. button:

enter image description here

2) Check your actual error:

enter image description here

Hope this helps someone.

+5
source

Just in case, this will help someone - I saw this error message. It turned out that I changed the database associated with my EF model and incorrectly configured the connection string.

0
source

Source: https://habr.com/ru/post/989952/


All Articles