我是新來的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