开发者

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

开发者 https://www.devze.com 2022-12-27 20:40 出处:网络
I have two tables th开发者_Go百科at 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 th

I have two tables th开发者_Go百科at 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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号