如何将以下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()
});
试一试,
from a in ProcessedCPLeaves
group a by new
{
LeaveTypeName = a.LeaveTypeName,
EmpUserName = a.EmpUserName,
ProcessingDate = a.ProcessingDate
} into g
select new
{
EmpUserName = g.Key.EmpUserName
LeaveTypeName = g.Key.LeaveTypeName
TotalCount = g.Count()
}