Linq - Group by week on the List

Viewed 8594

I want to group by week my data like this:

var result = stats.GroupBy(i => SqlFunctions.DatePart("week", i.date))
            .Select(g => new ReportModel
            {
                clicks = g.Select(x => x.clicks).Sum(),
                impressions = g.Select(x => x.impressions).Sum(),
                ...
            });

But I get this error:

This function can only be invoked from LINQ to Entities.

What's the problem and how can I fixed it?

2 Answers
Related