[英]LINQ group by doesn't work
我有這個LINQ查詢:
from p in Products
join c in Categories on p.CategoryID equals c.CategoryID
group p by p.Category into prices
select new {price = prices.Average(p => p.UnitPrice), name = p.Category.CategoryName }
我得到的錯誤是:
The name 'p' does not exist in the current context
為什么我不能在這里訪問? 我該怎么做才能解決這個問題?
你可以使用Key
:
...
group p by p.Category into prices
select new
{
price = prices.Average(p => p.UnitPrice),
name = prices.Key.CategoryName
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.