Click here了解如何使用代码优先方法来做到这一点。下面是原数据库第一道问答。
我正在使用实体设计器创建数据库优先模型。现在我想在 ProductId 和 ProductId 之间创建外键关系(见下文)。我查看了“添加新关联”,但无法连接这两个项目。有经验的人可以告诉我如何实现这一点吗?
最佳答案
根据Relationships/Associations with the EF Designer ,创建外键关联的步骤是:
- Right-click an empty area of the design surface, point to Add New, and select Association….
- Fill in the settings for the association in the Add Association dialog.
...填写关系详细信息时,请务必选中将外键属性添加到实体复选框。
关于entity-framework - 如何在 Entity Framework 中添加外键关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19591513/