如何将以下 SQL 查询转换为 LINQ?
SELECT [EmpUserName],[LeaveTypeName],Count([NoOfDays]) as 'Count'
FROM [NSL.LeaveSystem02].[dbo].[ProcessedCPLeaves]
GROUP BY [LeaveTypeName],[EmpUserName],[ProcessingDate]
请帮忙。
谢谢
如何将以下 SQL 查询转换为 LINQ?
SELECT [EmpUserName],[LeaveTypeName],Count([NoOfDays]) as 'Count'
FROM [NSL.LeaveSystem02].[dbo].[ProcessedCPLeaves]
GROUP BY [LeaveTypeName],[EmpUserName],[ProcessingDate]
请帮忙。
谢谢
试试这个,
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()
}
以下是方法语法
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()
});