using System.Collections.Generic;
using System.Collections.ObjectModel;
public string CreatedBy { get; set; }
public int AppointmentTypeID { get; set; }
public int GlaasStateID { get; set; }
public int AppointmentTypeID { get; set; }
public String Name { get; set; }
public static void Main()
List<ApptType> types = new List<ApptType>()
new ApptType() { AppointmentTypeID = 1, Name = "TA" },
new ApptType() { AppointmentTypeID = 2, Name = "TF" },
new ApptType() { AppointmentTypeID = 3, Name = "LECT" },
List<Appt> appts = new List<Appt>
new Appt() { CreatedBy = "BLambert", AppointmentTypeID = 1, GlaasStateID = 1 },
new Appt() { CreatedBy = "BLambert", AppointmentTypeID = 1, GlaasStateID = 1 },
new Appt() { CreatedBy = "BLambert", AppointmentTypeID = 1, GlaasStateID = 2 },
new Appt() { CreatedBy = "BLambert", AppointmentTypeID = 1, GlaasStateID = 3 },
new Appt() { CreatedBy = "rg", AppointmentTypeID = 1, GlaasStateID = 1 },
var ApptsByProcessor = from appt in appts
group appt by new { appt.CreatedBy, appt.AppointmentTypeID, appt.GlaasStateID } into grp
select new { AppointmentProcessor = grp.Key, Count = grp.Count() };
var typesLeftJoinedApptsByProcessor = from apptType in types
join apptByProcessor in ApptsByProcessor on apptType.AppointmentTypeID equals apptByProcessor.AppointmentProcessor.AppointmentTypeID into apptTypeLeftJoinApptByProcessor
from apptByProcessor in apptTypeLeftJoinApptByProcessor.DefaultIfEmpty()
AppointmentType = apptType,
AppointmentTypeID = apptType.AppointmentTypeID,
grp = apptTypeLeftJoinApptByProcessor
var newdata = typesLeftJoinedApptsByProcessor.SelectMany(x=>
y.AppointmentProcessor.CreatedBy,
y.AppointmentProcessor.GlaasStateID,
var newerdata = from t in types
join n in newdata on t.AppointmentTypeID equals n.AppointmentType.AppointmentTypeID into g
from z in g.DefaultIfEmpty()
Console.WriteLine(newdata.Count());
Console.WriteLine(typesLeftJoinedApptsByProcessor.SelectMany(x=>x.grp).Count());
Console.WriteLine(JsonConvert.SerializeObject(newerdata, Formatting.Indented));