2

I have a SQL Server query and I rewrite this query in c# by using LINQ.

In the T-SQL query, there is a sum like that:

SELECT Date, Name, SUM(1) AS ItemCount, SUM(ProductCount) AS ProductCount 
FROM somewhere
GROUP BY Date, Name

I write the SUM(ProductCount) in C# like x.Sum(i=>i.ProductCount) and it is working.

But I have no idea how can I write the SUM(1) in C#.

Edit: My LINQ

var list=_context.ProductList
.GroupBy(t=> new{ t.Date, t.Name})
.Select(i=> new ShipmentList(){ 
Date= i.Key.Created, 
Name=i.Key.Name, 
ItemCount= ?? , 
ProductCount=i.Sum(x=>x.ProductCount)}).ToList();

I search the ?? part in this code.

simoncare
  • 75
  • 1
  • 8

0 Answers0