entity framework - Get result with inner join and group by in LINQ -


i struggling group by, need list of teachers , total number of students responsible across of classes. need use linq expression

here er diagram enter image description here

linq

from _teacher in teachers join _class in classes on _teacher.id equals _class.teacherid  join _studentclasses in studentclasses on _class.id equals _studentclasses.classid  group _studentclasses _studentclasses.studentid _grouped  select new {_teacher, _class.name, _studentclasses.studentid} 

you can use columns have grouped by. think can this:

from _teacher in teachers join _class in classes      on _teacher.id equals _class.teacherid  join _studentclasses in studentclasses      on _class.id equals _studentclasses.classid  group _studentclasses  new {    teachername=__teacher.name,    classname=_class.name }  _grouped  select new  {     _grouped.key.teachername,      _grouped.key.classname,      stundetcount=_grouped.count() } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -