我有这个查询:
(from a in SickDays
join b in Class.Where(p => p.ID == myId) on a.Class_ID equals b.ID
join c in Student on a.Student_ID equals c.ID
group a by new { c.Name, c.Order } into ac
select new { Count = ac.Count(), Name = ac.Key.Name, Order = ac.Key.Order }
).OrderBy(f => f.Order)
这将返回:
Count | Name | Order
3 | Dave | a
2 | John | b
7 | Sally| c
但是我希望它返回这个:
Count | Name | Order
3 | Dave | a
2 | John | b
7 | Sally| c
0 | Mark | d
0 | Betty| e
更新: 使用@sixlettervariables 示例,这就是学生、班级和病假日的样子:
var Students = new List<Student>()
{
new Student { Id = 1, Name = "Al", Order = 'a' },
new Student { Id = 2, Name = "Betty", Order = 'b' },
new Student { Id = 3, Name = "Charles", Order = 'c' },
};
var Classes = new List<Class>()
{
new Class { Id = 1, Title = "A100" },
new Class { Id = 2, Title = "A200" },
};
var SickDays = new List<SickDay>()
{
new SickDay { Id = 1, StudentId = 1, ClassId = 1 },
new SickDay { Id = 2, StudentId = 1, ClassId = 1 },
new SickDay { Id = 3, StudentId = 1, ClassId = 2 },
new SickDay { Id = 4, StudentId = 1, ClassId = 2 },
new SickDay { Id = 5, StudentId = 2, ClassId = 1 },
};
好的,以上内容现在是正确的,很抱歉造成混淆!