by
8. July 2010 15:52
The EF4 bits are excellent but one of the pains i have had was how to use the EF designer and add a foreign key mapping to an entity. So you have a User entity and an Address entity and the Address entity has a UserId foreign key that links to the User Id property.
I kept running into an issue that said the Address entity wasn't mapped and specifically the foreign key. I had no idea what to do to solve this. I checked the Xml behind the EDMX and found that not storage model had been created to allow that mapping. This seems odd to me. I would think it would create it when you are working in the designer and make the update upon commit!?
Anyway, the resolution to this is to right-click the model and say Generate Database from Model. This creates the data scripts and once executed it creates the tables in your database and at the same time updates you entity model to allow the mapping to happen. All works after that.