BHS_TimeSheet
是我的数据库表,其中有一些记录。
Model.TimeSheet
是我在模型中创建的类。
Private db As DataFactoryDataContext
Public Sub New()
db = New DataFactoryDataContext
End Sub
Public Sub New(ByVal repository As DataFactoryDataContext)
db = repository
End Sub
Public Function GetTimeSheetByProject(ByVal wbs1 As String, ByVal wbs2 As String, ByVal wbs3 As String) _
As List(Of Model.TimeSheet) Implements ITimeSheetRepository.GetTimeSheetByProject
Return (From ts In db.BHS_TimeSheets _
Where ts.WBS1.Equals(wbs1) And ts.WBS2.Equals(wbs2) And ts.WBS3.Equals(wbs3) _
Select New Model.TimeSheet(ts.TSBatchNo, ts.Employee, ts.TransDate, ts.WBS1, ts.WBS2, ts.WBS3, ts.LaborCode, _
ts.RegHrs, ts.OvtHrs, ts.SpecialOvtHrs, ts.TransComment, ts.Status, ts.AuthorizedBy, _
ts.RejectReason, ts.ModDate)).ToList
End Function
答案 0 :(得分:2)
您的Linq-to-SQL声明
(From ts In db.BHS_TimeSheets
Where ts.WBS1.Equals(wbs1)
And ts.WBS2.Equals(wbs2)
And ts.WBS3.Equals(wbs3) _
基本上对应于这个SQL查询:
SELECT * FROM dbo.BHS_TimeSheets
WHERE WBS1 = (value for wbs1)
AND WBS2 = (value for wbs2)
AND WBS3 = (value for wbs3)
如果在SQL Server Management Studio中使用与{Linner-to-SQL代码中相同的wbs1, wbs2, wbs3
参数调用SQL查询,那么该SQL查询是否返回任何值?
更新:好的,所以SQL查询会返回结果 - 下一步:逐步处理Linq-to-SQL的内容。首先,试试这个 - 你得到任何结果??
Dim basicQueryResults = (From ts In db.BHS_TimeSheets
Where ts.WBS1.Equals(wbs1)
And ts.WBS2.Equals(wbs2)
And ts.WBS3.Equals(wbs3)
).ToList();
您生成的项目列表是否有.Count > 0
?
如果不是:那么Linq-to-SQL模型肯定有问题。您是否更改了数据库而未更新DBML文件?您可以删除DBML文件并再次执行 - 它现在可以工作吗?或者你仍然有相同的结果??