This is my first C# application in ASP.NET Core using Entity Framework Core and I'm trying to write the following MySQL query in Linq:
SELECT districtid, COUNT(id), MONTH(registerDate)
FROM StreetCrimes
GROUP BY districtid, MONTH(registerDate)
The problem I'm facing is writing the linq code. I've tried the following to get close to the answer:
var StreetCrimes = this.database.StreetCrimes
.Select(s => s.district)
.Count(s => s.id > 0)
.GroupBy(s => s.district)
.ThenBy(s => s.registerDate);
Any help making this possible would be appreciated.
My StreetCrime
class:
public class StreetCrime
{
public int id { get; set; }
public string caseNumber { get; set; }
public District district { get; set; }
public DateTime registerDate { get; set; }
public TimeSpan crimeTime { get; set; }
}