我正在调用DataContext对象的ExecuteQuery方法。我希望每行都有一个String和一个Integer,但是当我运行ToList函数时,我的所有值都不是0。我的所有结果应该是不同的字符串和数字。如果我直接运行它,我的查询运行完美,但ExecuteQuery返回垃圾而不是有效结果。造成这种情况的原因是什么?
提前谢谢。
编辑:
public function something as List(of Pair(of String, Integer))
Dim c As TTDataContext = ContextFactory.CreateDataContext()
Dim startValueLen = CStr(StartValue).Length
Dim query As String = "select top " & CStr(Limit) & " case " &
" when WONum like '0000%' then SUBSTRING(WONum, 5, Len(WONum) - 4) " &
" when WONum like '000%' then SUBSTRING(WONum, 4, Len(WONum) - 3) " &
" when WONum like '00%' then SUBSTRING(WONum, 3, Len(WONum) - 2) " &
" when WONum like '0%' then SUBSTRING(WONum, 2, Len(WONum) - 1) " &
" else WONum " &
" end as retVal, " &
" case " &
" when WONum like '0000%' then 1 " &
" when WONum like '000%' then 2 " &
" when WONum like '00%' then 3 " &
" when WONum like '0%' then 4 " &
" else LEN(WONum) " &
" end as retLen " &
" from TblWorkOrder " &
" where CompanyID = " & CStr(CompanyID) & " and LEN(WONum) >= " & CStr(startValueLen) & " and (WONum > '" & CStr(StartValue) & "' or LEN(WONum) > " & CStr(startValueLen) & ") " &
" order by retLen, retVal"
Dim temp = c.ExecuteQuery(Of Pair(Of String, Integer))(query)
Return temp.ToList
End Function
答案 0 :(得分:0)
问题的原因是我的Pair类有一个First和Second属性,我没有将结果作为First和second返回。因此问题的解决方案是将第一个值作为First返回,将第二个值作为Second返回,而不是retVal和retLen。