โค้ดที่ใช้
var data = from geoq in db.geo
join proq in db.province on geoq.GEO_ID equals proq.GEO_ID into g
from j in g
join comq in db.company on j.PROVINCE_ID equals comq.comp_province into g1
from j1 in g1
join stdq in db.student on j1.comp_id equals stdq.company_fk into g2
select new
{
idpark = geoq.GEO_ID,
namegeo = geoq.GEO_NAME,
numstd = g2.Count()
};
var data = from geoq in db.geo
join proq in db.province on geoq.GEO_ID equals proq.GEO_ID into j1
from j2 in j1.DefaultIfEmpty()
join comq in db.company on j2.PROVINCE_ID equals comq.comp_province into j3
from j4 in j3.DefaultIfEmpty()
join stdq in db.student on j4.comp_id equals stdq.company_fk into j5
from j6 in j5.DefaultIfEmpty()
group geoq by new { geoq.GEO_ID , geoq.GEO_NAME } into grouped
select new { GEO_ID = grouped.Key.GEO_ID , GEO_NAME = grouped.Key.GEO_NAME , Count = grouped.Count() };
from GEO geo
inner join Province pro geo.GEO_ID = pro.GEO_ID
inner join Company com pro.Prov_ID = com.Prov_ID
inner join Student stu com.Com_ID = stu.Com_ID