Schedule
表:
ScheduleId(PK), AirplaneId(FK), OriginId(FK), Duration-String
Airplane
表:
AirplaneId(PK), PlaneCode-String
Origin
表:
OriginId(PK), OriginName-String
我想要显示如下内容:
ScheduleId | PlaneCode | OriginName | Duration
Schedule.vb
Public Class Schedule
Public Property ID As Int32
Public Property Duration As String
'Foreign key of airplane_Id
Public Overridable Property Airplane As Airplane
'Foreign key of origin_Id
Public Overridable Property Origin As Origin
End Class
Airplane.vb
Public Class Airplane
Public Property ID As Int32
Public Property PlaneCode As String
End Class
Origin.vb
Public Class Origin
Public Property ID As Int32
Public Property OriginName As String
End Class
我的网格视图:
<asp:GridView ID="gvSearchFlight" runat="server" ItemType="CIM.Schedule" SelectMethod="gvSearchFlight_GetData" AutoGenerateColumns="false" GridLines="None">
GridView qazxsw poi:
SelectMethod
但我一直收到这个错误:
无法转换类型为'System.Collections.Generic.List Qazxsw Poi2 [CIM.Schedule,CIM.Airplane]]'的对象,以输入'System.Linq.IQueryable`1 [CIM.Schedule]'
编辑:我真的不知道如何写“选择新”语句..
Dim dbContext As New ApplicationDbContext
Public Function gvSearchFlight_GetData() As IQueryable(Of Schedule)
Dim schedules = (From sche In dbContext.Schedule
Join air In dbContext.Airplane
On sche.Airplane.ID Equals air.ID).ToList()
Return schedules
End Function
1[VB$AnonymousType_11
这就是我为解决问题所做的工作。
ScheduleInformation.vb
Public Class ScheduleInformation
Public Property Schedule As Schedule
Public Property Airplane As Airplane
Public Property Origin As Origin
End Class
GridView的SelectMethod
Public Function gvSearchFlight_GetData() As IQueryable(Of ScheduleInformation)
Dim schedules = (From sche In dbContext.Schedule
Join air In dbContext.Airplane On sche.Airplane.ID Equals air.ID
Join ori In dbContext.Origin On sche.Origin.ID Equals ori.ID
Select New ScheduleInformation())
Return schedules
End Function
然后,在我的标签中,我写道:
Public Class ScheduleInformation
Public Property Schedule As Schedule
Public Property Airplane As Airplane
Public Property Origin As Origin
End Class