entity-framework - 如何在 Entity Framework 中添加外键关系?

标签 entity-framework visual-studio

Click here了解如何使用代码优先方法来做到这一点。下面是原数据库第一道问答。

我正在使用实体设计器创建数据库优先模型。现在我想在 ProductId 和 ProductId 之间创建外键关系(见下文)。我查看了“添加新关联”,但无法连接这两个项目。有经验的人可以告诉我如何实现这一点吗?

foreign key

最佳答案

根据Relationships/Associations with the EF Designer ,创建外键关联的步骤是:

  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.

...填写关系详细信息时,请务必选中将外键属性添加到实体复选框。

另请参阅:Relationships, Navigation Properties, and Foreign Keys

关于entity-framework - 如何在 Entity Framework 中添加外键关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19591513/

相关文章:

c# - 如何检查可空 bool 值是否为真?

c# - dotMemory 和跟踪内存泄漏

c# - 引用 dll 路径的区域内的此注释的目的是什么? (系统. Action )

c# - 用 => 初始化(这样)

c# - 编辑实体时出现 DbUpdateConcurrencyException

c# - 将连接字符串传递给代码优先 DbContext

c# - 没有强制异常处理?

Visual Studio 2015 中未检测到 Android 手机

mysql - MySQL for Visual Studio 1.2.8 安装失败

r - 如果你已经有了 Rstudio,那么 RTVS 有什么用?