如何在Entity Framework中添加外键关系? [英] How to add foreign key relationship in Entity Framework?

查看:531
本文介绍了如何在Entity Framework中添加外键关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,创建外键关联的步骤如下:



  1. 右键单击设计曲面的空白区域,指向添加新建,然后选择关联...。

  2. 填写关联的设置在添加关联对话框中。


...一定要检查添加外部填写关系详细信息时,实体复选框的关键属性。



另请参见:关系,导航属性和外键


Click here to see how to do it while using a code first approach. Below the original database first approach question and answer.

I am using Entity Designer to create a database first model. Now I want to create a foreign key relationship between ProductId and ProductId (see below). I looked at the "add new association" but I cannot connect the two items. Can someone more experienced tell me how to accomplish this?

解决方案

According to Relationships/Associations with the EF Designer, the steps to create a foreign key association are:

  1. Right-click an empty area of the design surface, point to Add New, and select Association….
  2. Fill in the settings for the association in the Add Association dialog.

...being sure to check the Add foreign key properties to the Entity checkbox when filling in the relationship details.

See also: Relationships, Navigation Properties, and Foreign Keys

这篇关于如何在Entity Framework中添加外键关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆