I have a table called Orders the table has many rows but im only interested in two开发者_如何学Go in particular. I want to query the table so it returns the average ordered count of each product i want to know what is the average count of the ordered products, but now in total but per productID instead. How can this be done?
i tried this:
Dim ord = From e In db.Orders
Group e By e.ProductID Into grp
Select New With {.Id = e.ProductID, .Avg = grp.average}
but this does not work.
Solved it but had to wait for rep up.
Dim ord = (db.Orders.GroupBy(Function(n) n.ProductID, Function(key, values) New With {.ID = key, .Avg = values.Average(Function(n) n.Amount)})).GetEnumerator
精彩评论