0
我試圖重新在LINQ下面的SQL查詢返回JSON:全外連接和計數
SELECT a.Title, COUNT(b.ActionID) FROM labels a
FULL JOIN [Values] b ON a.ID = b.ID
GROUP BY a.Title
我想:
public ActionResult Json()
{
IEnumerable <object> query = (from a in db.Labels
join b in db.Values on a.ID equals b.ID
group b.ID by a.Title into grp
select new
{
Label = grp.Key,
Value = grp.Count()
}).ToList();
return Json(query, JsonRequestBehavior.AllowGet);
}
結果只會返回一個值標籤:
[{"Label":"New","Value":2}]
但我需要的是:
[
{"Label":"A","Value":2},
{"Label":"B","Value":0},
{"Label":"C","Value":0},
]