linq表达式错误:无法显示列名
我正在使用 LinqPad 4(坚果壳数据库),我试图显示(客户)名称,它是客户表中的一列。 我如何在此查询中显示名称,因为现在我收到错误:不包含“名称”的定义?
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 using LinqPad 4(nutshell database) and I am trying to display the (Customer) Name which is a column in the Customer table.
How can i display the Name in this query because now 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)
试试这个...
我假设您有一个包含(价格、客户 ID 和日期)列的购买表..
Try this...
I assume you have a Purchase table with (Price, CustomerID and Date) columns..
您已经按 CustomerID 进行分组,因此它是分组键。即在您的查询中,您应该说:
customerid = SalesByYear.Key
。不确定您的查询中的年份来自哪里。You've already grouped by CustomerID, therefore it is the grouping key. i.e. in your query, you should say:
customerid = SalesByYear.Key
. Not sure where the year comes from in your query.