linq 表达式错误:无法显示列?
我正在尝试将 linq 查询与另一个表连接起来。如何在客户表中显示姓名?我收到错误:不包含“名称”的定义?
from p in Purchases
join c in Customers on p.CustomerID equals c.ID
group p by p.Date.Year into SalesPerYear
select new {
customername= SalesPerYear.First().Name,
customerid= SalesPerYear.First().CustomerID,
totalsales= SalesPerYear.Sum(x=>x.Price)
}
i am trying to join my linq query with another table. How can I display the name in the Customer table? I am getting an error: does not contain a definition for 'Name'?
from p in Purchases
join c in Customers on p.CustomerID equals c.ID
group p by p.Date.Year into SalesPerYear
select new {
customername= SalesPerYear.First().Name,
customerid= SalesPerYear.First().CustomerID,
totalsales= SalesPerYear.Sum(x=>x.Price)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您按日期对
p
(即购买)进行分组 - 因此客户详细信息不再存在。试试这个:
或者:
You're grouping
p
(i.e. purchases) by date - so the customer details are no longer present.Try this instead:
Or alternatively:
SalesPerYear 是一个 IGrouping。您需要从 IGrouping 的 Value 属性访问 Name、CustomerID 等。
SalesPerYear is an IGrouping. You need to access Name, CustomerID etc off the Value property of the IGrouping.