Help with LINQ groyuping by multiple columns
Hi,, need some guidance in vb.net 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 :confused::confused:
Code:
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()
Re: Help with LINQ groyuping by multiple columns
try this:
Code:
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