System.Data.Entity.Core.EntityCommandExecutionException Occurred in MVC app Using EF

found out what the bug was. The query field is 'firstname' but my table column name is 'first'. They did not match. Once I changed the DB column name, it was working again.

One must be diligent to keep each in sync if the database is always in flux.

Why?

EF is simply a set of mappings, a snapshot in time, and whether those mappings are to tables or stored procedures, it does not matter.

For any subtle change(s) to column names or foreign key constraints can have ripple effects to any old mappings and they need to be remapped/scaffolded into new structure(s); otherwise hence weird behaviors from old mappings.

At times, those effects can create obvious errors like you found or even more insidious non obvious logical errors which can provide working (compiled) software with subtle logic bugs. I have seen the logic bugs by experience and they do happen.

So always be wary to keep the EF mappings in sync.


I answered to a different EF question but in a similar vein.

I had run into a situation where in EF a mapped stored proc at runtime failed because an internal change in the stored proc saw that a sql cast had stripped out a column name from the result, and EF (mapped before the changed) failed. I have a screen shot in my answer which shows that EF/db changes can have a deleterious effect:

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


In my case helped next:

1) press View Detail.. button:

enter image description here

2) Check your actual error:

enter image description here

Hope it helps for someone.