R – How To Remove Foreign Key Reference In Entity Framework

ado.netentity-frameworknet

I'm updating my model which is built by entity framework. I removed a entity from the designer and then there pops up a error said "Foreign key constraint 'FK_Table1_Table2' … no mapping specified for the table Table2. Now I really don't want to map Table2 into entities. What should I do to clear the edmx and avoid such error? Can I just map the foreign key in Table1 into a int32 field? Thanks!

I'm using EFv1.

Best Answer

I've found the Entity Framework designer leaves a lot to be desired so I found the best way is to edit the .edmx by hand.

The .edmx file contains 3 main sections, one which represents the storage model (database), one which represents the conceptual model and one section which represents the mapping between the two models

If I understand correctly, you have removed Table2 from the conceptual model and so you should remove anything related to it in the conceptual side of the EDMX. Chances are table 1 will still have an association to table 2 that you need to delete. Unfortunately manual edits to the .EDMX file will be overwritten if you ever use the designer to regenerate the model.