Reputation: 871
Need some help in linq
I want to achieve to get data, let say from '2014-09-01
' to '2014-10-30
'
and I want to group data, which have the same date, into 1 record, + count total occurence data for each date.
like this :
2014-09-01, 9 records
2014-09-12, 4 records
and so on..
Have tried this, I can get data within period and group by date, but not sure how to count data which occured within a given period for each date:
var data = CTX.application.Where(a => a.applied_date >= new Datetime(2014,9,1)
&& a.applied_date <= new Datetime(2014,10,30)
.GroupBy(g => g.applied_date))
Upvotes: 0
Views: 349
Reputation: 21825
Try this:-
var query = logs.Where(x => x.LogDate > new DateTime(2014, 09, 20) && x.LogDate < new DateTime(2014, 10, 12))
.GroupBy(x => x.LogDate).Select(x => new { LogDate = x.Key, Count = x.Count() });
Working Fiddle.
Upvotes: 1