我需要對 db 進行查詢以從我們網站中的 highchart 小部件獲取資料,這是我目前使用的代碼,
var highChartsData =
(from a in db.roomdetails
join b in db.ApplySchedule on a.RoomId equals b.RoomID
where b.Status == true
select new HighlinePie
{
Title = a.RoomName,
Date = b.MDate,
Value = db.ApplySchedule.Where(x => x.RoomID == a.RoomId).GroupBy(x=>x.MDate).Count(),
}).ToList();
這種方法的問題是現在獲取總數,但我需要的是基于日期的計數,例如,如果日期 12/09/20201 有兩個條目,而 14/09/20201 有三個條目,則資料應該是"標題,12/09/20201,2","標題,14/09/20201,3"。
uj5u.com熱心網友回復:
您必須使用分組:
var groupQuery =
from a in db.roomdetails
join b in db.ApplySchedule on a.RoomId equals b.RoomID
where b.Status == true
group b by new { a.RoomName, b.MDate } into g
select new HighlinePie
{
Title = g.Key.RoomName,
Date = g.Key.MDate,
Value = g.Count()
};
var highChartsData = groupQuery.ToList();
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/375672.html
標籤:C# 林克 asp.net-mvc-4
