Having got a chunk of my application working with Entity Framework 4.1, I needed to add a couple more tables. I created the entities and associations in the Model Viewer and then ask it to generate the database from the model.
Immediately I get a selection of validation errors and a pop-up informs me that I must clear all validation errors before I can generate the database.
The errors in question are all along the lines of:
Error 11007: Entity type ‘EntityName’ is not mapped.
Or
Error 11008: Association ‘AssociationName’ is not mapped.
I get this error once for each new Entity and Association I have created.
Now I get that they are not mapped to the database yet, this seems quite logical as they are totally new to the model. That is why I’m trying to use the “Generate Database From Model” tools to generate the database.
Am I understanding correctly that I cannot generate a new database from the model because the new Entities and Associations I have added to the Model are not already in the database? If so, how do I work around this?
It transpired that ( as suggested in comments by hdv ) there was another error in the .EDMX file which was being lost amongst the Error Message noise. This related to a field that I had used to key an association and later deleted without realising that the association depended on it.
The error message included a line in the .EDMX file so I closed it in the Model Editor and used
Open With > XML Editorto open the source, find the relevant line and delete the association. This flagged up a few more errors where that association was referenced from elsewhere and after removing those I could open the file in Model Viewer again and it allowed me to create the database.