I wrote a function that returns a DataTable Object. For the following code
Public Function GetArtikelsAbove50(ByVal limit As Integer) As DataTable
Dim query = _Set.Ten_Most_Expensive_Products.AsEnumerable.Where(Function(x) x.UnitPrice > limit) _
.GroupBy(Function(x) x.UnitPrice)
Return query.CopyToDataTable
End Function
query
is an System.Data.EnumerableRowCollection(Of SPTest.northwindDataSet.Ten_Most_Expensive_ProductsRow)
Object. The code runs and everything is good. But if I add:
.GroupBy(Function(x) x.UnitPrice)
the compiler underlinies the return object (query.CopyToDataTable
). query is now an System.Collections.Generic.IEnumerable(Of System.Linq.IGrouping(Of Decimal, SPTest.northwindDataSet.Ten_Most_Expensive_ProductsRow))
Object so CopyToDataTable is not a member of that anymore. Since I need the .GroupBy
Function (some goes for .Sum
)) I am looking for a way to use it in combination with the .CopyToDataTable
. Is that possible and if so, how can I accomplish it?
I thought, that mybe returning a DataView
Objeckt (with Return query.AsDataView
) would work, but same error.
Hint: During my research I found that in this question a user mentioned that the function .CopyToDataTable "has been restricted to IEnumerable and does not work for IEnumerable(of T)". I am not so familiar with Datasets and I am not sure if this helps to solve the problem. Just wanted to share the information, maybe it is helpful.