Invalid column name after mapping

2019-07-26 11:56发布

问题:

I have added a (bit\bool) column IsController to one of my tables

ALTER TABLE P_USER ADD IsController bit NOT NULL DEFAULT 0

Updated the edmx and added IsController to the MY_USER entity, then changed its name to IsControllerX and mapped it to the IsController from the table.

And set this inside the solution.domain.business cs file:

   public virtual bool IsControllerX { get; set; }

On debug I have the error:

An error occurred while executing the command definition. See the inner exception for details. InnerException: Invalid column name 'IsController'.

The error is with the IsController and not with IsControllerX! That is the name of the column that I mapped to - the name of the column inside the database!

Can someone please explain why I get this error?

回答1:

HOW did you update your model and your generated classes??

In the EDMX, you should select the Update Model From Database option from the context menu, and then in the Update Wizard, you should pick your table that has been modified:

Doing this will properly update your EDMX and it works just fine in my scenario. Did you do it this way, and it still fails?? Or did you just do it manually ??