linq表达式错误:无法显示列名

发布于 2024-12-07 10:49:26 字数 372 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹泡泡o 2024-12-14 10:49:26

试试这个...

我假设您有一个包含(价格、客户 ID 和日期)列的购买表..

from p in Purchases  
group p by p.Date.Year into SalesByYear 
select new { 
customerid = SalesByYear.First().CustomerID, 
year=SalesByYear.Key, 
TotalVal = SalesByYear.Sum(g => g.Price) 
} 

Try this...

I assume you have a Purchase table with (Price, CustomerID and Date) columns..

from p in Purchases  
group p by p.Date.Year into SalesByYear 
select new { 
customerid = SalesByYear.First().CustomerID, 
year=SalesByYear.Key, 
TotalVal = SalesByYear.Sum(g => g.Price) 
} 
吻风 2024-12-14 10:49:26

您已经按 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文