我正在使用VB.Net并具有以下LINQ查询...
Dim ACFTTail5 = (From tailcounts In db.TailCounts _
Where tailcounts.Model = "UH-60A" _
Group tailcounts By _
tailcounts.Tail, tailcounts.Model _
Into g = Group Order By Tail _
Select Tail, rdf = CStr(g.Sum(Function(p) _ p.TailCount))).ToArray
我正在尝试获得如下所示的二维数组..
ACFTTail5 (0)(0) “Tail-a”
ACFTTail5 (0)(1) “RDF-a”
ACFTTail5 (1)(0) “Tail-b”
ACFTTail5 (1)(1) “RDF-b”
ACFTTail5 (2)(0) “Tail-c”
ACFTTail5 (2)(1) “RDF-c”
ETC ..
我试过......
Dim ACFTTail5(,) As String
ACFTTail5 = (From tailcounts In db.TailCounts _
Where tailcounts.Model = "UH-60A" _
Group tailcounts By _
tailcounts.Tail, tailcounts.Model _
Into g = Group Order By Tail _
Select Tail, rdf = CStr(g.Sum(Function(p) p.TailCount)))
但是得到以下错误......
“无法转换类型为'System.Data.Linq.DataQuery 1[VB$AnonymousType_4
的对象2 [System.String,System.String]]'来键入'System.String [,]'。”
我们将非常感谢任何建议......
由于
答案 0 :(得分:0)
如果您不太关心强制它进入二维数组,您可以只允许编译器分配匿名IQueryable类型并将其用于迭代:
Dim ACFTTail5 = (From tailcounts In db.TailCounts _
Where tailcounts.Model = "UH-60A" _
Group tailcounts By _
tailcounts.Tail, tailcounts.Model _
Into g = Group Order By Tail _
Select Tail, rdf = CStr(g.Sum(Function(p) p.TailCount)))
然后您可以使用For each
迭代器来循环浏览所需的任何内容。
修改强>
我没有测试过这个小小的片段,但你应该可以使用List
Dim ACFTTail5 as List(Of String())
ACFTTail5 = new List(Of String())(From tailcounts In db.TailCounts _
Where tailcounts.Model = "UH-60A" _
Group tailcounts By _
tailcounts.Tail, tailcounts.Model _
Into g = Group Order By Tail _
Select new String() { Tail, rdf = CStr(g.Sum(Function(p) p.TailCount)) })
Dim ACFTTail5_2d_Array as String(,) = ACFTTail5.ToArray()
我在这里使用的关键是直接将它选择到一个新类(在本例中为字符串数组),并将其保存在专门用于字符串数组的List中。然后你应该能够将它发送到字符串数组的字符串数组。