简体   繁体   中英

Mapping foreign keys on EF 4 without creating a new Edmx file

I created edmx file by unchecking the option for creating entites for foreign keys.So there is no mapping for my foreign key fields. Is it possible to map foreign keys without creating a new edmx file ? If possible How.? I created .edmx from a database which I had already.I am using VS 2012 .Thanks .

Right click in the edmx, hit update model from database. There's a checkbox for foreign keys in there. Is that what you're looking for?

If there are any problems with edmx model generation (which can happen if you change the options and try a partial refresh), the simplest way to refresh the model completely is to select everything (eg Ctrl-A) and delete the lot from the model.

Then right click the empty model page and select "Update Model from Database", selecting all the tables you wish to include again, along with the appropriate options checked or unchecked (like "Include foreign key columns in the mode").

This sequence tends to cleanup problems that occur if you try to do a partial update. It will of course remove any customisation you have made to the mode (extra navigation etc), but is generally to easiest solution to edmx problems.

You can delete and add the model again. I hope that will work. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM