如何将以下SQL查询转换为LINQ?

SELECT [EmpUserName],[LeaveTypeName],Count([NoOfDays]) as 'Count'
FROM [NSL.LeaveSystem02].[dbo].[ProcessedCPLeaves]
GROUP BY [LeaveTypeName],[EmpUserName],[ProcessingDate]


请帮忙。

谢谢

最佳答案

以下是方法语法

 ProcessedCPLeaves
.GroupBy(item => new {
                 LeaveTypeName = item.LeaveTypeName,
                 EmpUserName = item.EmpUserName,
                 ProcessingDate = item.ProcessingDate
}).Select (grouping => new {
                 EmpUserName =grouping.Key.EmpUserName,
                 LeaveTypeName = grouping.Key.LeaveTypeName,
                 TotalCount= grouping.Count()
});

关于c# - 如何将带有group by子句的SQL select Count转换为LINQ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14109363/

10-09 08:47