我最近在EntityFramework项目中设置了一个类,它将一个组合键指定为一个组合键。
I recently set up a class in an EntityFramework project which designated a couple of its members as a composite key.
然而,当它创建时数据库从它它给出错误
However, when it came to time to create the database from this it gave the error
无法确定类型NNNNN的复合主键排序。使用ColumnAttribute或HasKey方法来指定复合主键的顺序。
Unable to determine composite primary key ordering for type 'NNNNN'. Use the ColumnAttribute or the HasKey method to specify an order for composite primary keys.
我知道如何解决问题,但我是只是想知道为什么它关心订单。不是一个复合主键,只是一组列,在其上键入记录,而不需要任何特定的排序?
I know how to solve the problem, but I was just wondering why it cares about the order. Isn't a composite primary key just a set of columns on which to key the records, without any particular ordering necessary?
推荐答案这很重要,因为主键的顺序在数据库中很重要。由于主键(通常)是集群的,并且始终是索引,无论密钥是按名字,姓氏,SSN或SSN,姓氏,名字排序都会产生巨大的差异。如果我在查询表时只有SSN,而PK是唯一的索引,那么我将看到后者具有很高的性能,而前者将扫描完整的表。
It matters because the order of primary keys matter in the database. Since primary keys are (usually) clustered, and always indices, whether the key is ordered as First Name, Last Name, SSN or SSN, Last Name, First Name, makes a huge difference. If I only have the SSN when I'm querying the table, and the PK is the only index, I'll see GREAT performance with the latter, and a full table scan with the former.
更多推荐
为什么主键顺序很重要?
发布评论