【发布时间】:2012-08-25 16:46:22
【问题描述】:
我的项目中有几个模型确实应该使用识别关系,但出于速度和简单性的原因,我将它们设置为具有唯一的自动增量主键。例如,联系人中的电子邮件地址:
Public Class EmailAddress
'This is currently the primary key
Public Property EmailAddressID As Integer
'These three properties really make a composite primary key in an identifying relationship with contacts
Public Property ContactID As Integer
Public Property Address As String
Public Property Domain As String
End Class
我对此设置有两个问题:
- 在复合键中包含
nvarchar字段是否真的会减慢数据库速度,足以保证不使用它(因为我在学校被引导相信)? - 如果 1 为“是”,是否有方法(在数据注释或 Fluent API 中)通知 EF 这实际上是与人工主键的识别关系,因此 reap the benefits(在标题“识别和识别的注意事项”下)非识别关系”)?
【问题讨论】:
标签: sql-server entity-framework ef-code-first foreign-keys