我是新来的LINQ to SQL,我想知道如何实现在LINQ是这样的:LINQ组按月问题
Month Hires Terminations
Jan 5 7
Feb 8 8
Marc 8 5
我这有,到目前为止,我认为有是不是有问题,但我不知道:
from term1 in HRSystemDB.Terminations
group term1 by new { term1.TerminationDate.Month, term1.TerminationDate.Year } into grpTerm
select new HiresVsTerminationsQuery
{
Date = Criteria.Period,
TerminationsCount = grpTerm.Count(term => term.TerminationDate.Month == Criteria.Period.Value.Month),
HiresCount = (from emp in HRSystemDB.Persons.OfType<Employee>()
group emp by new { emp.HireDate.Month, emp.HireDate.Year } into grpEmp
select grpEmp).Count(e => e.Key.Month == Criteria.Period.Value.Month)
});
在此先感谢。
向我们展示您的数据库架构将有所帮助。 – Blindy 2010-01-20 21:51:32
什么是“Criteria.Period”和“Criteria.Period.Value.Month”? – 2010-01-20 21:52:45
是什么让你感到不确定是对的?它是否编译?你有没有试过运行它?它是否提供您期望的结果? – 2010-01-20 21:58:36