3

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.

5
  • Are you using this table as a temporary table for stored procedures? Commented Aug 4, 2009 at 12:44
  • 1
    No, it's actually the most frequently used table of the whole database. Commented Aug 4, 2009 at 13:54
  • Do you get this error when you run a stored procedure or when you run a linq statement directly against the table? Commented Aug 4, 2009 at 19:41
  • From all Stored Procedures that return the entity. I haven't tried accessing any data direct via linq, but my guess is it wouldn't be a problem, since the intellisense picks up on it. Commented Aug 5, 2009 at 6:34
  • I delete the DBNameEntities from the <ConnectionStrings> in Web.Config and then delete the .emdx and readd... sofar this has worked (unfortunately, I seem to have to do it about 1/2 the time I modify the DB... Commented Oct 18, 2016 at 0:10

6 Answers 6

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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."
Is there a newer version than 3.5 SP1?
1

Just had the same issues as above. Tried removing the entity from the edmx, tried removing and re-adding the function import, and finally rebuilt using a complex type in the function import and that didn't work either.

I realize this error can occur for really any scenario where there is a mismatch but we found the issue was in the stored proc we used for the function import. The stored proc was using specific select columnname, columnname etc and the new column we added to the table was not in that list. To test, we used the *, updated the EDMX and it resolved our issue.

1 Comment

+1: having so many stored procedures that selects columns by naming them one by one, was my problem. This taught me whenever you want to bind your sp to an entity, you must use select *.
0

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.

1 Comment

NO... This is awful... I delete it and delete the DBEntities connection string and readd.. its faster and bulletproof...(so far?!)
0

For me it was an issue where I altered an entity (vertical entity splitting), but one of my stored procedures wasn't pulling data for that new field. I added it (in the SP) and now everything runs fine.

Comments

0

Unless it's simply adding a new item, This throws an error just about every time I try to "Update model from database" ...

The solution is luckily 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. (so far!?)

Comments

0

If you Re-Add the DataModel you will lose all DataBindings - especially bindings of controls on your form (like DbGrid). I have fixed this issue manually editing the DataModel.edmx file in external Editor.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.