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

この問題の原因は、ペア クラスに First および Second プロパティがあり、結果を First および Second として返さなかったことです。したがって、この問題の解決策は、retVal と retLen の代わりに、最初の値を First として返し、2 番目の値を Second として返すことです。

于 2012-06-22T20:39:44.223 に答える