0

我正在调用我的 DataContext 对象的 ExecuteQuery 方法。结果,我希望每一行都有一个字符串和一个整数,但是当我运行 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
4

1 回答 1

0

问题的原因是我的 Pair 类具有 First 和 Second 属性,而我没有将结果返回为 First 和 second。因此问题的解决方案是将第一个值返回为 First,将第二个值返回为 Second,而不是 retVal 和 retLen。

于 2012-06-22T20:39:44.223 回答