简体   繁体   English

在EF 4上映射外键而不创建新的Edmx文件

[英]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. 我通过取消选中为外键创建entites的选项来创建edmx文件。因此我的外键字段没有映射。 Is it possible to map foreign keys without creating a new edmx file ? 是否可以在不创建新的edmx文件的情况下映射外键? If possible How.? 如果可能的话。 I created .edmx from a database which I had already.I am using VS 2012 .Thanks . 我从已经使用的数据库中创建了.edmx。我正在使用VS 2012.谢谢。

Right click in the edmx, hit update model from database. 右键单击edmx,从数据库中点击更新模型。 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. 如果edmx模型生成有任何问题(如果更改选项并尝试部分刷新可能会发生这种情况),完全刷新模型的最简单方法是选择所有内容(例如Ctrl-A)并从模型中删除批次。

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. 它当然会删除您对该模式所做的任何自定义(额外的导航等),但通常是最简单的解决edmx问题的方法。

You can delete and add the model again. 您可以再次删除并添加模型。 I hope that will work. 我希望这会奏效。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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