Is it beneficial to use multicolumn (composite) primary keys when using Linq to SQL?

后端 未结 2 1005
臣服心动
臣服心动 2021-01-12 18:22

Is it beneficial to use multicolumn (composite) primary keys for a many to many relationship table when using Linq to SQL?

Or should I just add an identity column as

2条回答
  •  梦谈多话
    2021-01-12 19:15

    If it makes sense in your domain to have a multi-column composite key, then use one. Otherwise use the usual identity column as the surrogate primary key.

    EDIT: that was general advice and not taking into account any technical aspects of implementing using LINQtoSQL. These may be of interest:

    How to: Handle Composite Keys in Queries (LINQ to SQL)

    LINQ To SQL Samples

    Linq to SQL DTOs and composite objects

提交回复
热议问题