linq多表联合,group by分组查询问题,求高手
有两个数据表,siteInfo表(siteID,经度lon,纬度lat,siteName)和shopInfo表(shopID,date,earning),两个表通过siteID关联,
我想查询结果按日期显示出SiteID对应的所有shopID的earning的总和,以及siteID所对应的lon,lat字段,我是这样做的:var query = from a in this.ObjectContext.siteInfo
join b in this.ObjectContext.shopInfo
on a.siteID equals b.siteID
group new { a.Lon, a.Lat, a.siteID, b.date, b.earning, b.shopID} by b.date into g
select new
{
date = g.Key,
SiteID= g.FirstOrDefault().siteID,
Longitude = g.FirstOrDefault().Lon
Latitude = g.FirstOrDefault().Lat,
Totalearning= g.Sum(t => t.earning)
};
而查询结果,却只能显示一个日期的siteID对应的所有shop的earning总和,以及siteID所对应的lon,lat字段,我该怎样修改代码?请教了。
------解决方案--------------------举个例子说明你想要的效果,,, 没看明白
------解决方案--------------------var query =from a in this.ObjectContext.siteInfo
join b in this.ObjectContext.shopInfo
on a.siteID equals b.siteID
group a by new { a.Lon, a.Lat, a.siteID, b.date} into g
select new {SiteID=g.Key.siteID, Longitude=g.Key.Lon, Latitude=g.Key.Lat, date=g.Key.date, Totalearning= g.Sum(t => t.earning)};