Please, see an example:
void Main()
{
List<Visit> Visits = new List<Visit>
{
new Visit(1, new DateTime(2015,2,24), "A"),
new Visit(2, new DateTime(2015,2,23), "S"),
new Visit(2, new DateTime(2015,2,24), "D"),
new Visit(4, new DateTime(2015,2,22), "S"),
new Visit(2, new DateTime(2015,2,22), "A"),
new Visit(2, new DateTime(2015,2,22), "B"),
new Visit(3, new DateTime(2015,2,23), "A"),
new Visit(1, new DateTime(2015,2,23), "A"),
new Visit(1, new DateTime(2015,2,24), "D"),
new Visit(4, new DateTime(2015,2,24), "S"),
new Visit(4, new DateTime(2015,2,22), "S"),
new Visit(2, new DateTime(2015,2,24), "S"),
new Visit(3, new DateTime(2015,2,24), "D")
};
var qry = Visits.GroupBy(v=>new{v.VisitDate, v.PersonelId})
.Select(g=>new{
VisitDate = g.Key.VisitDate,
PersonelId = g.Key.PersonelId,
A = g.Where(d=>d.VisitTypeId=="A").Count(),
B = g.Where(d=>d.VisitTypeId=="B").Count(),
D = g.Where(d=>d.VisitTypeId=="D").Count(),
S = g.Where(d=>d.VisitTypeId=="S").Count()
});
var qry1 = Visits.GroupBy(v=>new{v.VisitDate, v.PersonelId})
.Select(g=>new{
VisitDate = g.Key.VisitDate,
PersonelId = g.Key.PersonelId,
subject = g.GroupBy(f => f.VisitTypeId).Select(m => new { Sub = m.Key, Score = m.Count()})
});
}
public class Visit
{
private int id = 0;
private DateTime vd;
private string vt = string.Empty;
public Visit(int _id, DateTime _vd, string _vt)
{
id = _id;
vd = _vd;
vt = _vt;
}
public int PersonelId
{
get{return id;}
set{id = value;}
}
public DateTime VisitDate
{
get{return vd;}
set{vd = value;}
}
public string VisitTypeId
{
get{return vt;}
set{vt = value;}
}
}