Pretty new to LINQ and I think what I'm trying to do should be easy. I have a product list ( ProductId, ProductDesc), and I'm trying to pull out a subset of this list and group it using ProductId. From there, I would like to bind this subset to the View list. Here is the query I'm working on:
productCounts = (from record in wowReportData
group record by record.ProductID
into grouping
orderby grouping.Key
select new topProduct
{
ProductID = grouping.Key,
Quantity = grouping.Count(),
Name = grouping.
}).ToList();
and here is the class I'm trying to populate:
public class topProduct
{
public string ProductID { get; set; }
public int Quantity { get; set; }
public string Name { get; set; }
public topProduct() { }
public topProduct(string productId, string productDesc, int downloadCount)
{
this.ProductID = productId;
this.Name = productDesc;
this.Quantity = downloadCount;
}
}
I worked fine just displaying a ProductIdcounter, but I need to add a description to the display as well. I am confused about how to add a product description when I do grouping.
source
share