troubleshooting Question

Linq query is failing

Avatar of Anthony Matovu
Anthony MatovuFlag for Uganda asked on
Visual Basic.NETASP.NET.NET Programming
1 Comment1 Solution1443 ViewsLast Modified:
I have the code below and i am getting the error message
Unable to cast object of type 'VB$AnonymousDelegate_0`2[System.Object,System.Int32]' to type 'System.IConvertible'.Couldn't store <VB$AnonymousDelegate_0`

at line     workRow("package_key") = q.package_key, i really dont know how to go about this. I am just leaning LINQ


 Dim tmpquery = From obj_perhour In tmp_perhour.AsEnumerable() _
               Group obj_perhour By customerid = obj_perhour.Field(Of Decimal)("msisdn_nsk"), _
               time_key = obj_perhour.Field(Of Decimal)("time_key"), _
               base_station_key = obj_perhour.Field(Of Decimal)("base_station_key"), _
               faf_ind = obj_perhour.Field(Of String)("faf_ind") _
                Into grp = Group _
                  Select New With _
                       { _
                         .msisdn = customerid, .time_key = time_key, .base_station_key = base_station_key, .faf = faf_ind,
                         .package_key = Function(x) If((x.Field(Of Decimal)("package_key") = 21437 Or _
                                                        x.Field(Of Decimal)("package_key") = 22102 Or _
                                                        x.Field(Of Decimal)("package_key") = 21448 Or _
                                                        x.Field(Of Decimal)("package_key") = 18998 Or _
                                                        x.Field(Of Decimal)("package_key") = 21395), 1, _
                                                    If((x.Field(Of Decimal)("package_key") = 21437 Or _
                                                        x.Field(Of Decimal)("package_key") = 21353 Or _
                                                         x.Field(Of Decimal)("package_key") = 21361), 2, _
                                                    If((x.Field(Of Decimal)("package_key") = 612362 Or _
                                                        x.Field(Of Decimal)("package_key") = 359292 Or _
                                                        x.Field(Of Decimal)("package_key") = 605772 Or _
                                                        x.Field(Of Decimal)("package_key") = 1078419 Or _
                                                        x.Field(Of Decimal)("package_key") = 692109), 3, 4))),
                         .ccost = grp.Sum(Function(x) x.Field(Of Decimal)("ccost")),
                         .cdur = grp.Sum(Function(x) x.Field(Of Decimal)("cdur")),
                         .calls = grp.Count(Function(x) x.Field(Of Decimal)("msisdn_nsk"))

        createactivitylog("Created per hour table", startt, Now)
        startt = Now

        Dim dt As New DataTable("perhour")

        dt.Columns.Add("msisdn", GetType(Decimal))
        dt.Columns.Add("time_key", GetType(Decimal))
        dt.Columns.Add("base_station_key", GetType(Decimal))
        dt.Columns.Add("faf", GetType(String))
        dt.Columns.Add("package_key", GetType(Decimal))
        dt.Columns.Add("ccost", GetType(Decimal))
        dt.Columns.Add("cdur", GetType(Decimal))
        dt.Columns.Add("calls", GetType(Decimal))

        i = 0
        For Each q In tmpquery
            Dim workRow As DataRow = dt.NewRow()
            workRow("msisdn") = q.msisdn
            workRow("time_key") = q.time_key
            workRow("base_station_key") = q.base_station_key
            workRow("faf") = q.faf
            workRow("package_key") = q.package_key
            workRow("ccost") = q.ccost
            workRow("cdur") = q.cdur
            workRow("calls") = q.calls
            i += 1
              If i Mod 10000 = 0 Then Application.DoEvents()
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 1 Comment.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 1 Comment.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004