I an using EF6 database first design in a web application. There is one entity that is involved in two 1-to-many relationships (the E2 in this example):
E1 <--- E2 ---> E3
E1 and E3 both have a navigation property for E2 (called E2s). When I try to ListView of E3, I get the error listed in the title. If I remove the navigation property for E2 from E3, everything works just fine! I've tried looking all over google to no avail. Any help/direction would be appreciated.
Added on 5/15:
tmg - hope this is what you are wanting.
This would be the 'E2' in my example:
Imports System
Imports System.Collections.Generic
Partial Public Class contact
Public Property contact_id As Integer
Public Property implementation_id As Integer
Public Property contact_type_id As Integer
Public Property name As String
Public Property user_id As String
Public Property is_main_contact As Boolean
Public Property email_address As String
Public Overridable Property contact_type As contact_type
Public Overridable Property implementation As implementation
End Class
The next two are the E1 and E3:
Imports System
Imports System.Collections.Generic
Partial Public Class contact_type
Public Property contact_type_id As Integer
Public Property contact_type_description As String
Public Overridable Property contacts As ICollection(Of contact) = New HashSet(Of contact)
End Class
Imports System
Imports System.Collections.Generic
Partial Public Class implementation
Public Property implementation_ID As Integer
Public Property user_ID As String
Public Property comments As String
Public Property creation_date As Nullable(Of Date)
Public Property customer_name As String
Public Property customer_global_name As String
Public Property customer_address As String
Public Property customer_country As String
Public Property service_order_number As String
Public Property title As String
Public Property contact_name As String
Public Overridable Property Country As Country
Public Overridable Property supportDetail As support_detail
Public Overridable Property tradeCompliance As trade_compliance
Public Overridable Property statusEffDates As ICollection(Of implementation_status_eff_date) = New HashSet(Of implementation_status_eff_date)
Public Overridable Property hwsData As hws_data
Public Overridable Property documents As ICollection(Of document) = New HashSet(Of document)
Public Overridable Property contacts As ICollection(Of contact) = New HashSet(Of contact)
End Class
This is the list view code:
Imports System.Web.ModelBinding
Public Class ImplementationList
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Public Function GetImplementations(<QueryString("id")> categoryId As System.Nullable(Of Integer)) As IQueryable(Of implementation)
Dim db = New RFI_SDM.RFI_DataEntities
Dim query As IQueryable(Of implementation) = db.implementations
Return query
End Function
End Class
And finally the code for RFI_DataEntities:
Imports System
Imports System.Data.Entity
Imports System.Data.Entity.Infrastructure
Partial Public Class RFI_DataEntities
Inherits DbContext
Public Sub New()
MyBase.New("name=RFI_DataEntities")
End Sub
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
Throw New UnintentionalCodeFirstException()
End Sub
Public Overridable Property Countries() As DbSet(Of Country)
Public Overridable Property implementations() As DbSet(Of implementation)
Public Overridable Property replacement_type() As DbSet(Of replacement_type)
Public Overridable Property service_level_choice() As DbSet(Of service_level_choice)
Public Overridable Property support_detail() As DbSet(Of support_detail)
Public Overridable Property tat_end_choice() As DbSet(Of tat_end_choice)
Public Overridable Property tat_measurement_basis() As DbSet(Of tat_measurement_basis)
Public Overridable Property tat_start_choice() As DbSet(Of tat_start_choice)
Public Overridable Property regions() As DbSet(Of region)
Public Overridable Property contacts() As DbSet(Of contact)
Public Overridable Property contact_type() As DbSet(Of contact_type)
Public Overridable Property hws_data() As DbSet(Of hws_data)
Public Overridable Property implementation_mgr() As DbSet(Of implementation_mgr)
Public Overridable Property implementation_service_level() As DbSet(Of implementation_service_level)
Public Overridable Property implementation_status() As DbSet(Of implementation_status)
Public Overridable Property implementation_status_eff_date() As DbSet(Of implementation_status_eff_date)
Public Overridable Property trade_compliance() As DbSet(Of trade_compliance)
Public Overridable Property implementation_type() As DbSet(Of implementation_type)
Public Overridable Property documents() As DbSet(Of document)
Public Overridable Property document_type() As DbSet(Of document_type)
Public Overridable Property LCM_Data() As DbSet(Of LCM_Data)
Public Overridable Property LCM_document() As DbSet(Of LCM_document)
End Class
The actual error I'm getting is:
Schema specified is not valid. Errors: The relationship 'RFI_DataModel.FK_contact_contact_type' was not loaded because the type 'RFI_DataModel.contact' is not available.
The relationship 'RFI_DataModel.FK_contact_implementation' was not loaded because the type 'RFI_DataModel.contact' is not available.
If I remove the 'contact' navigation property from the contact_type and implementation classes, the list view loads without issue.