I have the SQL and trying to convert ti to Linq query. I need to group records by several fields, how to do that in Linq?
var statistic = DataAccess.Instance.Statistics.Where(
p =>
p.DateStamp >= minDate &&
p.DateStamp <= DateTime.UtcNow && p.UserId == userId &&
p.Url.Contains(url)
).
GroupBy(p=>p.PageTitle //How to group by second(Url) field?
SELECT PageTitle
, Url
, Count(*) As [Count]
FROM Statistic
WHERE URL like @url
AND DateSpan BETWEEN @dateRange1 AND @dateRange2
AND UserId = @UserId
GROUP BY PageTitle, Url
ORDER BY Count(*) DESC, Url;
You need to group by an anonymous type: