开发者

Counting orders and grouping them, linq to sql

开发者 https://www.devze.com 2023-03-28 06:55 出处:网络
I have a table called Orders the table has many rows but im only interested in two开发者_如何学Go in particular.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消