加入3表并返回

时间:2011-11-19 09:52:25

标签: vb.net silverlight entity-framework linq-to-entities

我有3张表,其中包括时间表,时间表和咨询时段 我希望将它们组合起来,以便所有数据都能够轻松检索

时间表正在

1. TimetableID
2. Lecture ID
3. ClassVenue
4. ClassStartTime
5. ClassEndTime

附表

1. ScheduleID
2. LectureID
3. ScheduleVenue
4. ScheduleStartTime
5. ScheduleEndTime

咨询槽

1. ConsultationID
2. LectureID
3. StudentID
4. ScheduleID
5. remark

这是我在元数据中的代码

Partial Public Class CombinationOfTSC
    <Key()> _
    Public Property LectureID() As String
        Get
            Return m_LectureID
        End Get
        Set(value As String)
            m_LectureID = value
        End Set
    End Property
    Private m_LectureID As String

    Public Property StudentID() As String
        Get
            Return m_StudentID
        End Get
        Set(value As String)
            m_StudentID = value
        End Set
    End Property
    Private m_StudentID As String

    Public Property ttID() As String
        Get
            Return m_ttID
        End Get
        Set(value As String)
            m_ttID = value
        End Set
    End Property
    Private m_ttID As String

    Public Property ttClassVenue() As String
        Get
            Return m_ttClassVenue
        End Get
        Set(value As String)
            m_ttClassVenue = value
        End Set
    End Property
    Private m_ttClassVenue As String

    Public Property ttClassStartTime() As DateTime
        Get
            Return m_ttClassStartTime
        End Get
        Set(value As DateTime)
            m_ttClassStartTime = value
        End Set
    End Property
    Private m_ttClassStartTime As DateTime

    Public Property ttClassEndTime() As DateTime
        Get
            Return m_ttClassEndTime
        End Get
        Set(value As DateTime)
            m_ttClassEndTime = value
        End Set
    End Property
    Private m_ttClassEndTime As DateTime

    Public Property scID() As String
        Get
            Return m_scID
        End Get
        Set(value As String)
            m_scID = value
        End Set
    End Property
    Private m_scID As String

    Public Property scVenue() As String
        Get
            Return m_scVenue
        End Get
        Set(value As String)
            m_scVenue = value
        End Set
    End Property
    Private m_scVenue As String

    Public Property scStartTime() As DateTime
        Get
            Return m_scStartTime
        End Get
        Set(value As DateTime)
            m_scStartTime = value
        End Set
    End Property
    Private m_scStartTime As DateTime

    Public Property scEndTime() As DateTime
        Get
            Return m_scEndTime
        End Get
        Set(value As DateTime)
            m_scEndTime = value
        End Set
    End Property
    Private m_scEndTime As DateTime

    Public Property cID() As String
        Get
            Return m_cID
        End Get
        Set(value As String)
            m_cID = value
        End Set
    End Property
    Private m_cID As String

    Public Property cRemark() As String
        Get
            Return m_cRemark
        End Get
        Set(value As String)
            m_cRemark = value
        End Set
    End Property
    Private m_cRemark As String
End Class

在我的域类中,代码将是

Public Function GetCoTSC(lectureID As String) As IQueryable(Of CombinationOfTSC)
        Dim CSC As IQueryable(Of CombinationOfTSC) = From c In ObjectContext.ConsultationSlots Join s In ObjectContext.Schedules On c.ScheduleID Equals s.ScheduleID Join t In ObjectContext.TimeTables On t.LectureID Equals s.LectureID Where c.LectureID = s.LectureID = t.LectureID Select New CombinationOfTSC() With { _
                      .cID = c.ConsultationID, _
            .cRemark = c.Remark, _
            .StudentID = c.StudentID, _
             .LectureID = s.LectureID, _
            .scStartTime = s.ScheduleStartTime, _
            .scEndTime = s.ScheduleEndTime, _
            .scID = s.ScheduleID, _
            .scVenue = s.ScheduleVenue, _
              .ttID = t.TimeTableID, _
              .ttClassVenue = t.ClassVenue, _
              .ttClassStartTime = t.ClassStartTime, _
            .ttClassEndTime = t.ClassEndTime}
        Return CSC
    End Function

我在c.LectureID = s.LectureID = t.LectureID遇到错误 我希望通过讲义ID获得3个表的组合,因为有3个表的讲座ID。 任何人都有帮助。

2 个答案:

答案 0 :(得分:0)

我不相信你可以拥有x = y = z。你有没有尝试将它们分成两对?

答案 1 :(得分:0)

尝试Where c.LectureID = s.LectureID and s.LectureID = t.LectureID代替Where c.LectureID = s.LectureID = t.LectureID