Sono nuovo di LINQ to SQL e vorrei sapere come ottenere qualcosa di simile in LINQ:gruppo LINQ per mese questione
Month Hires Terminations
Jan 5 7
Feb 8 8
Marc 8 5
ho questo finora, e ci credo c'è qualcosa che non va, ma non sono sicuro:
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)
});
Grazie in anticipo.
Mostrandoci il tuo schema di database sarebbe d'aiuto. – Blindy
Cosa sono 'Criteria.Period' e' Criteria.Period.Value.Month'? –
Cosa ti fa sentire insicuro che sia giusto? Compila? Hai provato a farlo funzionare? Dà i risultati che ti aspetti? –