Entity Framework issue after adding a column to DB table

I needed to add a new NVARCHAR column to a table in my DB. So I added a column and then activated Visual Studio to update the EDMX file for the Entity Framework.

I ran the update model from the database over everything that only led to the fact that the "data reader is incompatible" - these were. Therefore, I renamed the entire table in the database, updated EDMX from the database, renamed the table back to its original name, started the update again, and then created a new import of functions for all affected stored procedures. But I still get the same error:

The data reader is incompatible with the specified "[Model]. [Entity]". a member of the type, '[Column]', does not have a corresponding column in the data reader with the same name.

I looked around a bit, and this seems to be a common mistake if the column name is different in the database and structure. However, this is not so; they have the same name.

I can access the column in the code through [Entity] .Context. [Column], so I don’t quite understand what the data reader is complaining about.

I have run out of ideas, so any help is appreciated.

+3
source share
6 answers

Turns out EDMX was great, but the designer stopped updating Designer.cs in my project for some odd reason.

.

0

, . " ", EDMX, XML. , . . - (, ), . .

+2

, . edmx, , , import, .

, , , , proc, . select, .., , , . *, EDMX .

+1

, ( ), . ( SP), .

0

If it just does not add a new item, it causes an error almost every time I try to "Update model from database" ...

The solution, fortunately, is very simple -

1) Open Web.config, find <connectionStrings> node 
2) Delete the DBNameEntities <connectionStrings>  
     - this way you do not have to modify any references to your emdx model
2) Delete the ADO.NET Entity Data Model (.emdx) 
3) Re-add the ADO.NET Entity Data Model (.emdx) with the same name.

Its faster and bulletproof. (still!?)

0
source

If you re-add the DataModel, you lose all DataBindings - especially the bindings of the controls in your form (e.g. DbGrid). I fixed this problem manually by editing the DataModel.edmx file in an external editor.

0
source

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


All Articles