I'm using Entity Framework 4 with the Model First approach.
I started the project, designed the entities and generated the database. Everything worked fine.
Then I needed to go back and add another entity to my model. However, as I drag an entity to the EDMX I get this error:
Alright! I just need to map Entity1 to a table.. But hey! I'm using Model First approach, I expect it to create the table for me when I generate the DDL.
How do I work around this error?
This is because of the way EF4 works with model-first.
When you first create a model-first model, it's in a state that the SSDL does not exist. You can drag entities, associate them and so forth and yet, if you take a look at the SSDL on the EDMX file, you will see that none of the entities have an associated storage table in the SSDL.
That changes when you click the Generate Database From Model
context menu item. The confusing part is that this action does more than simply generating a DDL script. In fact, it changes the EDMX file to include SSDL information. From this point on, the EDMX file will enter a state in which every entity in the designer/CSDL must map to an entity in the SSDL. If one does not map, it will trigger a compile time error:
No mapping specified for the following EntitySet/AssociationSet - (EntityName)
Another interesting fact is that it's not the kind of error that will prevent compilation. It will, indeed, generate the output class library. Shouldn't it be a warning or something?
To prevent this error, All you have to do after inserting a new entity is to Generate Database From Model
again. That will update the SSDL and fix the mappings.
EDIT
If you are not using model-first and you "update from database", you will also have this error in the case you deleted a table in DB Server. This is because Entity Framework will not automatically delete the entity for you. Delete the entity manually and the error will go away.