Search code examples
.netentity-frameworkdatabase-firstmappingexception

having problem with updating model entity framework in database-first approach


I've used entity framework in my projects and i used database-first approach almost in each time that i change the database ( adding/removing a field to existing table or add new table ) after updae the model , it's becaming unvalid and i receive some strange and irrational errors.

for example : Column 'XXX' specified as part of this MSL does not exist in MetaDataWorkspace

or

Error 10021: Duplicated Schema element encountered. or System.Data.Entity.Core.MappingException

and i must do some unrelated task such as

deleteing all tables from model , closing and reopening the visual studio , undo pending changes , deleteing all project data , etc ...

to releave these errors.

what's the problem ? did i do somethings wrong ?


Solution

  • After some days searching I found the solution. Try this:

    1 Delete all tables or fields which you added to emdx file ( back to previous state ) and give a successful rebuild.

    2 Add new fields and tabales.

    3 Save emdx file.

    4 Right click on emdx file and click on "Run Custom Tool".

    5 Rebulid the project.

    If your problem isn't solved, try to substitute step 2 with step 3.