I have the following classes in my mvc model and I'm using EF
public class Patient
{
[Key()]
public int PatientId { get; set; }
public string Name { get; set; }
}
public class Treatment
{
[Key()]
public int Id { get; set; }
[ForeignKey("Patient")]
public int PatientId { get; set; }
public Patient Patient { get; set; }
[DataType(DataType.DateTime)]
public DateTime TreatmentDate { get; set; }
}
I want to display the names of the Patients and in the same row the number of treatments they received.
The 2 solutions i can think of but looking for something more elegant:
- Iterating my Patients and for each count its treatments
- Group Treatments and count. Then Join between that result and Patient.
Thanks!