I have a sql table named Consult it represents consults(treatments) of physical therapists
ConsultID ConsultDate Therapist Location
I want to present this data summarized per week, starting 28 weeks ago till current week
Like:
Location Week-1 Week-2 Week-3 ..... Week-28
Amsterdam 41 38 34 55
Utrecht 65 56 46 46
How can I do this in Linq? I have the following:
public ActionResult Therapist(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
DateTime startDate = DateTime.Now.StartOfWeek(DayOfWeek.Monday).AddDays(-168);
DateTime endDate = DateTime.Now.StartOfWeek(DayOfWeek.Sunday);
var TherapistConsult = from row in db.Consults
where ((row.Therapist == id) && (row.ConsultDate > startDate) && (row.ConsultDate < endDate))
group row by row.Location into g
where g.FirstOrDefault() != null
select new
{
Location = g.Key,
// Need a loop here for 28 weeks in the past till this week
// WeekN = g.Count(x => x.Week == N),
};
return View(TherapistConsult.ToList());
}