troubleshooting Question

putting or condition in a linq

Avatar of Anthony Matovu
Anthony MatovuFlag for Uganda asked on
.NET ProgrammingASP.NETVisual Basic.NET
3 Comments1 Solution57 ViewsLast Modified:
I have built a linq query as below and so far i think it is fine,

Please advise me if i could built better, i am extremely new to linq queries,

secondary: how do i improve the second last line

  .mou_onn_tot_bno = grp.Sum(Function(x) If(x.Field(Of String)("utype") = "UG", x.Field(Of Decimal)("cdur"), 0)),

to include the condition (lower(wallet_type_cd) = 'loyalty'" & " or lower(wallet_type_cd)='bonus' or lower(wallet_type_cd)='promo')

I have managed with the and operator in the last line (advise me if i could do it better) but failing with the or operator


   Dim tbl_time As DataTable = ds.Tables("ctime")
        Dim tbl_perhour As DataTable = ds.Tables("perhour")
        Dim tbl_area As DataTable = ds.Tables("areas")
        Dim tbl_basestation As DataTable = ds.Tables("station")
        Dim tbl_country As DataTable = ds.Tables("country")

        TextBox1.Text = Now
        TextBox1.Refresh()


        Dim query = From obj_perhour In tbl_perhour.AsEnumerable() Join obj_time In tbl_time.AsEnumerable() _
                    On obj_perhour.Field(Of Integer)("time_key") Equals obj_time.Field(Of Integer)("time_key") _
                    Join obj_area In tbl_area.AsEnumerable() _
                    On obj_perhour.Field(Of Integer)("wallet_cd") Equals obj_area.Field(Of Integer)("wallet_cd") _
                    Join obj_basestation In tbl_basestation.AsEnumerable() _
                    On obj_perhour.Field(Of Integer)("base_station_key") Equals obj_basestation.Field(Of Integer)("base_station_key") _
                    Join obj_country In tbl_country.AsEnumerable() _
                    On obj_perhour.Field(Of Integer)("number_prefix_key") Equals obj_country.Field(Of Integer)("number_prefix_key")
                    Group obj_perhour By customerid = obj_perhour.Field(Of Integer)("msisdn"), _
                    time_hour = obj_perhour.Field(Of DateTime)("time_hour"), _
                    cellid = obj_perhour.Field(Of DateTime)("cellid"), _
                    sitename = obj_perhour.Field(Of DateTime)("sitename") _
                    Into grp = Group _
                       Select New With _
                            { _
                              .msisdn = customerid, .time_hour = time_hour, .cellid = cellid, .sitename = sitename, _
                              .rev_onn_tot_nbn = grp.Sum(Function(x) If(x.Field(Of String)("utype") = "UG", x.Field(Of Decimal)("ccost"), 0)),
                              .mou_onn_tot_nbn = grp.Sum(Function(x) If(x.Field(Of String)("utype") = "UG", x.Field(Of Decimal)("cdur"), 0)),
                               .mou_onn_tot_bno = grp.Sum(Function(x) If(x.Field(Of String)("utype") = "UG", x.Field(Of Decimal)("cdur"), 0)),
                              .rev_onn_voi_nbn = grp.Sum(Function(x) If(x.Field(Of Int16)("utype") = 44, If(x.Field(Of String)("utype") = "UG", x.Field(Of Decimal)("ccost"), 0), 0))}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros