SqlFunctions.DatePart(and other such functions) cannot be called the usual method. It can only be used as part of a database query (s IQueryable). Therefore, you need to use a different approach, for example:
stats.GroupBy(i => CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(
i.date, CalendarWeekRule.FirstDay, DayOfWeek.Monday));
Pay attention to the culture used, as well as the parameters GetWeekOfYear(which is considered the first week of the year and is considered the first day of the week).
source
share