我想LINQ到組通過日期,但顯示在文本LINQ組通過,然後顯示(DD MMM)
這裏的日期時間是我的代碼
var groups = _uow.Orders.GetAll()
.Where(x => x.Created > baselineDate)
.GroupBy(x => x.Created.ToString("yyyy-MM-dd"));
var orders = new
{
Day = groups.Select(g => g.Key).ToArray(),
Total = groups.Select(g => g.Sum(t => t.Total)).ToArray(),
};
結果(不好放在圖表的標籤)
{"Day": [2, 3, 4, 5], "Total": [9999.00, 9999.00, 9999.00, 9999.00] }
但我想這(每月)
"Day": ['Jan', Feb', 'Mar', 'Apr'], "Total": [9999.00, 9999.00, 9999.00, 9999.00] }
或每日
"Day": ['Jan 1', 'Jan 2', 'Jan 3', 'Jan 4'], "Total": [9999.00, 9999.00, 9999.00, 9999.00] }
請諮詢我則DateTime.ToString(),我可以玩。
謝謝大家。
這應該是一個評論 –
是啊,我知道如何使用的ToString( 「MMMM」)或任何別人stringFormat。但是當我使用LINQ進行分組時,它不起作用。 – riseres
@riseres是否將linq用於對象? Linq to SQL? EF? NHibernate的? – ChaseMedallion