【发布时间】:2020-06-03 09:41:42
【问题描述】:
我尝试使用 Linq 查询计算属于申请人的记录,但它没有返回 expatced 结果。发生乘法。 实际申请者有:
- 2 个应用程序
- 6 门课程
如何连接表以获得正确的值(2 和 6)?
谢谢!
var q = from application in this.SzakokRepository.GetAll()
join course in this.ErettsegiRepository.GetAll() on application.JelentkezoId equals course.JelentkezoId
join applicants in this.JelentkezokRepository.GetAll() on application.JelentkezoId equals applicants.Id
where applicants.Id == jelentkezoID
select new
{
Jelentkezo = applicants, //1 pieces
Szak = application, //2 pieces
Erettsegi = course, //6 pieces
};
var result = from g in q
group g by g.Jelentkezo.Id into grp
select new HelperErettsegiSzak
{
JId = grp.Key,
CountedApplications = grp.Count(), //12 pieces
CountedCourses = grp.Select(x => x.Erettsegi.Id).Count(), //12 pieces
};
return result.ToList();
【问题讨论】:
-
请显示示例数据,您期望它返回什么以及实际返回什么。