Results 1 to 2 of 2

Thread: Help with LINQ groyuping by multiple columns

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009

    Help with LINQ groyuping by multiple columns

    Hi,, need some guidance in linq
    i have a data table with the following columns

    ItemCode, ItemDescription,Height,Width,Quantity, Price

    need to group rows by Description, height and width and sum the quantity

    attempted this
    Dim q = From tbl In ocom.ds.Tables("table").AsEnumerable()
            '        Group tbl By tbl.Field(Of String)("ItemDescription"), tbl.Field(Of Decimal)("w"), tbl.Field(Of Decimal)("H") Into Comps()

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Chelmsford UK

    Re: Help with LINQ groyuping by multiple columns

    try this:

    Dim q = (From row In ocom.ds.Tables("table").AsEnumerable() _
                    Group row By i = row.Field(Of String)("ItemCode"), _
                    d = row.Field(Of String)("ItemDescription"), _
                    w = row.Field(Of Decimal)("Width"), _
                    h = row.Field(Of Decimal)("Height"), _
                    p = row.Field(Of Decimal)("Price") _
                    Into Group _
                    Select New With { _
                    .ItemCode = i, _
                    .ItemDescription = d, _
                    .Height = h, _
                    .Width = w, _
                    .Quantity = Group.Sum(Function(r As DataRow) r.Field(Of Integer)("Quantity")), _
                    .Price = p}).Tolist

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width