I’m getting a cyclical reference error on creating a db the against SqlCe4.0 client in EF Code First 4.3. I have attached a picture of my desired db schema, to be clear. FYI, I have successfully created my desired schema in SQL Server 2008.
The referential relationship will result in a cyclical reference that is not allowed. [ Constraint name = FK_Routes_Seasons_SeasonID ]
- Routes has a 1-many relationship to Seasons
- Contracts has a 1-many relationship to Routes
- Contracts has a 1-many relationship to Seasons

My code for the classes is:
Public Class Route
Public Property RouteID as Integer
Public Property SeasonID as Integer
Public Overridable Property Season As Season
Public Overridable Property Contracts As ICollection(Of Contract)
End Class
Public Class Season
Public Property SeasonID as Integer
Public Overridable Property Routes As ICollection(Of Routes)
Public Overridable Property Contracts As ICollection(Of Contract)
End Class
Public Class Contract
Public Property ContractID As Integer
Public Property RouteID As Integer
Public Overridable Property Route As Route
Public Property SeasonID As Integer
Public Overridable Property Season As Season
End Class
It’s not necessarily that it’s cyclical, but that you’re having multiple references in the same table in a delete tree. See this post and this post
In your table its:
You’ll need to set it so that one of these relationships does not cascade delete. I’m not familiar with VB, but in C# you could setup fluent like this: