LINQ - join the By group and get the average

SQL:

SELECT DeptId,avg(Marks) FROM StudentTb s JOIN StudInDepartment d on s.StudentId = d.StudentId GROUP BY DeptId 

Convert to 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) }; 

An empty list of results is received.

Expanding the result set in debug mode. It shows that the latency is evaluated by the function

Need help with this.

+4
source share
1 answer

The query works fine, as it is, at least in my layout, which I just threw together ... maybe this has something to do with how the database is structured ... In my layout, I have studentID as foreign the key to the StudInDepartment table (ha!), and even this simplified query works fine

 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) }; 

The message you received "function timeout" may be a Visual Studio debugging problem, cannot help you there, theres other threads from stackoverflow that discuss this as well.

+7
source

All Articles