我需要通过table:scan_LogEntry来检索关系数据,我知道如何通过运行多个linq-sql查询来检索所有这些数据,但是我很确定这不是一种非常有效的方法。我目前正在运行此语句,以从scan_LogEntry检索数据块。但是我想显示所有名称而不是所有主键。我一直在阅读有关如何执行此操作的信息,但是我发现的解释太复杂了,无法缠住我的头。目前正在像这样调出数据。
Public Class form_LogEntry_2
Private STleanappscontext As New STleanappsDataContext
Private scanbindsource As New BindingSource
Private Sub form_LogEntry_2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim begdt As DateTime = New DateTime(2014, 8, 4)
Dim enddt As DateTime = New DateTime(2014, 8, 5)
Dim logentryquery = From scan_LogEntries In STleanappscontext.scan_LogEntries
Where scan_LogEntries.tstStart >= begdt And scan_LogEntries.tstStart <= enddt
Select scan_LogEntries
DataGridView1.DataSource = logentryquery
DataGridView1.AutoResizeColumns()
End Sub
End Class
scan_LogEntries表通过以下各列(userCode,projectCode,actionCode,departmentCode)与其他4个表保持多对一关系,是否有一种简单的方法可以让我检索此数据,而无需循环浏览我的列表4次并查找每个主表。个别地钥匙?
使用Join语句链接其他表
Dim logentryquery = From scan_LogEntries In STleanappscontext.scan_LogEntries
Join user In Usertable
On user.id Equals scan_LogEntries.usercode
Where scan_LogEntries.tstStart >= begdt And scan_LogEntries.tstStart <= enddt
Select scan_LogEntries, user.name
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句