简体   繁体   English

在实体框架中以多对多关系创建复合主键

[英]Creating Composite primary keys in a many-to-many relationship in Entity Framework

I have two tables that are connected via a join table in a many-to-many relationship in the Entity Framework. 我有两个通过实体框架中的多对多关系通过联接表连接的表。 I need to add a composite primary key in the join table for the two columns that are related to the joined tables via standard foreign keys but I'm sure how to do that. 我需要在联接表中为通过标准外键与联接表相关的两列添加一个复合主键,但是我确定该怎么做。

If your join table has a composite key on both foreign keys, the Entity Framework designer in VS2008/2010 should pick up on that. 如果您的联接表在两个外键上都有一个组合键,则VS2008 / 2010中的Entity Framework设计器应对此进行选择。

SQL: SQL:

CREATE TABLE MyTable
(
  ColumnFK1  int,
  ColumnFK2  int

PRIMARY KEY (ColumnFK1, ColumnFK2)
)

If the table is already created you can modify the primary key in Management Studio. 如果已创建表,则可以在Management Studio中修改主键。

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

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