Click here to Skip to main content
16,017,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i do have a requirement that to get the sum result based on the no of records per month.
i have written the code as following.

C#
var Interviews = spe.Interviews
                .Where(w => w.InterviewDate.Year == year)
                .Join(spe.Recruiters, i => i.Recruiter, r => r.RecruiterId, (i, r) => new
                {
                    r.RecruiterId,
                    i.InterviewDate
                }).GroupBy(gp => new { RecruiterId = gp.RecruiterId, InterviewDate = gp.InterviewDate })
                .Select(x => new { RecruiterId = x.Key.RecruiterId, InterviewDate = x.Key.InterviewDate, InterviewCount = x.Count() }).ToList();


Note:- In the above code i am getting the count i.e interview count by date , but the count which i want is per month, please help me to achieve this!!!
Posted

1 solution

C#
var Interviews = spe.Interviews
                .Where(w => w.InterviewDate.Year == year)
                .Join(spe.Recruiters, i => i.Recruiter, r => r.RecruiterId, (i, r) => new
                {
                    r.RecruiterId,
                    i.InterviewDate
                }).GroupBy(gp => new { RecruiterId = gp.RecruiterId, Month= gp.InterviewDate.Month })
                .Select(x => new { RecruiterId = x.Key.RecruiterId, InterviewMonth = x.Key.Month, InterviewCount = x.Count() }).ToList();


if you need to get month as string replace
C#
Month= gp.InterviewDate.Month
with
C#
Month= gp.InterviewDate.ToString("MMM")
 
Share this answer
 
v2
Comments
pavan_ kumar 4-Dec-14 1:59am    
thanks, its working
DamithSL 4-Dec-14 2:05am    
you are welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900