I am using EF 4 code first, and I am having a heck of a time here. I keep getting the error:
{"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."}
Consider the following code. If I comment out the Foreign Key ID fields, it generates its own and it works, but if I don't then I get the error.
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
So I am wondering a few things:
Do I have to create the Foreign Key property and the navigation property? Do I just create the navigation property on the child object? Do I just create the navigation property on the parent object?
Anyone have any ideas? Thanks!!