We help IT Professionals succeed at work.
Get Started

Linq query is failing

1,440 Views
Last Modified: 2016-02-08
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
Comment
Watch Question
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE