I have an object MyObject that contains a date.
I have the following query where TheMonth and TheYear are parameters:
var MyQuery = from a in MyModelDC.MyTable
where a.Month == TheMonth
where a.Year == TheYear
select new MyObject
{
var1 = a.Day,
var2 = (from b in MyModel.MyTable
where b.Month == a.Month
where b.Year == a.Year
select b.Identity).Count()
};
I’d like to group the results so that each day occurs only once. Var 2 is a count and at the moment the row of the count is being repeated for each occurrence of Identity instead of being unique per day.
Thanks.
If I understand your requirements correctly, I think this will do what you ask:
Here we first group each item by the day it refers to, then we count each item in the groups so that we only include the items for that group’s specific day.
Update
To use MyObject as the output, you can do this: