Link to home
Start Free TrialLog in
Avatar of Anthony Matovu
Anthony MatovuFlag for Uganda

asked on

Linq query is failing

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

aNTHONY



 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
            dt.Rows.Add(workRow)
            i += 1
              If i Mod 10000 = 0 Then Application.DoEvents()
        Next
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial