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

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

问题描述

<一个href=\"http://stackoverflow.com/questions/5542864/how-should-i-declare-foreign-key-relationships-using-$c$c-first-entity-framework#5543702\">Click这里来看看如何在使用code第一种方式来做到这一点。下面的原始数据库第一种方法的问题和答案。

我使用实体设计器来创建数据库第一个模型。现在,我想创建和产品编号产品编号(见下文)之间的外键关系。我看着新增的关联,但我不能连接两个项目。更有经验的人能告诉我如何做到这一点?


解决方案

根据关系/协会与EF设计师,创建一个外键关联的步骤是:


  

      
  1. 右键单击设计图面的空白区域,指向添加新,然后选择协会...。

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

  4.   

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

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

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

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

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