I want to get the count of rows by date for each day this month, like this:
Date count
1/03/2013 18
2/03/2013 41
28/03/2013 12
29/03/2013 14
How to write the query for that?
I want to get the count of rows by date for each day this month, like this:
Date count
1/03/2013 18
2/03/2013 41
28/03/2013 12
29/03/2013 14
How to write the query for that?
So, I assume you have some table with a datetime field in which you have the date "1/03/2013" 18 times, meaning you have 18 rows in that table with that date.
Then you should get the count of each day of a month in a year by something like this:
var year = 2013;
var month = 3;
var q = from t in DBContext.TableName
where t.DateField.Year == year && t.DateField.Month == month
group t by t.DateField.Date
into g
select new
{
dateField = g.Key,
countField = g.Count()
};
See also the LINQ to SQL Samples