开发者

linq expression error:cant display column name

开发者 https://www.devze.com 2023-04-10 08:52 出处:网络
I am using LinqPad 4(nutshell开发者_如何学Python database) and I am trying to display the (Customer) Name which is a column in the Customer table.

I am using LinqPad 4(nutshell开发者_如何学Python 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)
}


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) 
} 


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.

0

精彩评论

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

关注公众号