首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连接3表并返回

连接3表并返回
EN

Stack Overflow用户
提问于 2011-11-19 17:52:25
回答 2查看 59关注 0票数 0

我有三张表,分别是时刻表,日程表和会诊时刻表,我希望把它们结合起来,这样所有的数据都可以很容易地检索出来

时间表已经有了

代码语言:javascript
复制
1. TimetableID
2. Lecture ID
3. ClassVenue
4. ClassStartTime
5. ClassEndTime

日程安排

代码语言:javascript
复制
1. ScheduleID
2. LectureID
3. ScheduleVenue
4. ScheduleStartTime
5. ScheduleEndTime

咨询时段

代码语言:javascript
复制
1. ConsultationID
2. LectureID
3. StudentID
4. ScheduleID
5. remark

以下是我的元数据代码

代码语言:javascript
复制
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

在我的域类中,代码将是

代码语言:javascript
复制
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遇到错误,我希望通过lectureID获得3个表的组合,因为有3个表上有讲座ID。任何人都可以帮助我们。

EN

回答 2

Stack Overflow用户

发布于 2011-11-19 17:58:24

我不相信你能得到x=y=z。你试过把它们分成两两吗?

票数 0
EN

Stack Overflow用户

发布于 2011-11-19 23:27:44

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8193214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档