【发布时间】:2011-04-04 03:23:30
【问题描述】:
我首先使用的是 EF 4 代码,我在这里玩得很开心。我不断收到错误:
{"Introducing FOREIGN KEY constraint 'SalesRepresentative_SalesOrders' on table 'SalesOrders' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors."}
考虑以下代码。如果我注释掉外键 ID 字段,它会生成自己的字段并且可以正常工作,但如果我不这样做,则会收到错误消息。
Public Class SalesOrder
Inherits EntityBase(Of SalesOrder)
#Region "Members/Properties"
Public Property ID As Integer
'Public Property CustomerID As Integer
'Public Property CustomerLocationID As Integer
'Public Property SalesRepresentativeID As Integer
'Public Property SalesOrderStatusID As Integer
Public Overridable Property Customer As Customer
Public Overridable Property CustomerLocation As CustomerLocation
Public Overridable Property Items As ICollection(Of SalesOrderItem)
Public Overridable Property Status As SalesOrderStatus
Public Overridable Property SalesRepresentative As SalesRepresentative
#End Region
End Class
Public Class SalesRepresentative
Inherits EntityBase(Of SalesRepresentative)
#Region "Members/Properties"
Public Property ID As Integer
Public Property FirstName As String
Public Property LastName As String
Public Overridable Property Customers As ICollection(Of Customer)
Public Overridable Property SalesOrders As ICollection(Of SalesOrder)
#End Region
End Class
所以我想知道一些事情:
我是否必须创建外键 属性和导航 财产?我只是创建 孩子的导航属性 目的?我只是创建 父级上的导航属性 对象?
有人有什么想法吗?谢谢!!
【问题讨论】:
-
我更喜欢“指数”......但这只是我。 :)
标签: entity-framework entity-framework-4.1