views:

1308

answers:

2

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

I ran update model from database on everything, which only resulted in "data reader is incompatible"-errors. So I renamed the whole table in the DB, updated EDMX from database, renamed the table back to the original name, ran update again, and then created new function imports 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've looked around a bit, and this seems to be a common error if the column name is different in the database and framework. This is however not the case, they have the same name.

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

I've run out of ideas, so any help welcome.

A: 

Updating the model replaces the store schema, but not the client schema or the mapping. To start with "a clean slate", back up your current EDMX, then open it as XML. Remove all references to the table, then close and open in the graphical error. Build. If you have any errors (perhaps broken links to the deleted table), fix them. Then update model to re-add the table.

Craig Stuntz
Jikes, that file is a mine field! Plus, this table is pretty much FK:ed in all other tables, so does that mean I have to delete all those tables too? I really must say, to manually have to edit the EDMX file to add a simple column to a table is nothing short of ridiculous. And I don't mean that to criticize you, Craig. It's kind of a serious flaw in the entity framework.
Marcus L
Well, I'd agree that the EF designer (as distinct from the EF runtime) in 3.5 SP1 has a number of flaws. But you don't generally have to do this "to add a simple column to a table." More like, "when you add a table to the model and then delete it and want to get the designer back to square one."
Craig Stuntz
Is there a newer version than 3.5 SP1?
Marcus L
.NET 4.0 is in beta now.
Craig Stuntz
A: 

Turns out the EDMX was fine, but the designer has, for some odd reason, stopped update Designer.cs in my project.

Had to go in and manually edit it.

Marcus L