LINQ - 联同集团通过并获得平均 [英] LINQ - join with Group By and get average
问题描述
SQL:
SELECT DeptId,avg(Marks) FROM StudentTb s
JOIN StudInDepartment d on s.StudentId = d.StudentId
GROUP BY DeptId
转换成Linq的:
var deptRpts = from s in this.ObjectContext.StudentTb
join d in this.ObjectContext.StudInDepartment on s.StudentId equals d.StudentId
group s by d.DeptId into grp
select new {
DeptId = grp.Key,
AverageMarks = grp.Average(ed=>ed.Marks)
};
有一个空的结果列表。
在调试mode.Its同时扩大了结果集显示错误的功能评价超时
While expanding the result-set in debug mode.Its shows error function evaluation timed out
需要这个帮助。
推荐答案
查询工作正常的,至少在我的模拟了,我只是把在一起......它可能是与数据库是如何结构....在我的模拟了我有studentID作为一个外键StudInDepartment(哈哈!)表和连这个简单的查询工作确定
The query works fine as is, at least in my mock up I just threw together ... it may have something to do with how the database is structured....in my mock up I have the studentID as a foreign key to the StudInDepartment (ha!) table and even this simplified query works ok
var deptRpt2 = from d in ctx.StudInDepartment
group d by d.DeptId into grp
select new {
Dept = grp.Key,
AverageMarks = grp.Average(ed=>ed.StudentTb.Marks)
};
您收到功能评价超时可能是在Visual Studio的调试问题,不能帮你那里,那里有其他线程关闭计算器的讨论为好。
The message you received "function evaluation timed out" may be the Visual Studio debugger issue, can't help you there, theres other threads off stackoverflow that discuss it as well.
这篇关于LINQ - 联同集团通过并获得平均的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!