【问题标题】:joining 3 table and return加入 3 个表并返回
【发布时间】:2011-11-19 09:52:25
【问题描述】:

我有 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 遇到错误 我希望通过 LectureID 获得 3 个表格的组合,因为 3 个表格上有讲座 ID。 任何人都可以帮忙。

【问题讨论】:

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


    【解决方案1】:

    我不相信你可以拥有 x=y=z。您是否尝试过将它们分开成对?

    【讨论】:

    • 大声笑。我同意。但是知道怎么做吗?你说的成对是什么意思?有什么例子吗?
    • 不知道能不能用 AND 分隔。 c.LectureID = s.LectureID AND c.LectureID = t.LectureID AND s.LectureID = t.LectureID。
    • nw i 使用 s.lectureID = t.lectureID 进行测试
    • 现在一切正常。唯一的问题是我无法在其中收到任何物品。有什么想法吗?
    • 您是否尝试过完全删除 where 子句并查看连接是否正确?
    【解决方案2】:

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

    【讨论】:

    • 试过了。我认为我有加入的问题,因为我删除了 t 对象。还是什么都没有显示>
    猜你喜欢
    • 2017-11-07
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 2012-04-03
    • 2016-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多