2

我希望 Linq 返回一个数组。为了绘制图表。

这是我的代码

var orders = _uow.Orders.GetAll()
            .Where(x => x.Created > baselineDate)
            .GroupBy(x => x.Created.Day)
            .Select(c => new {Day = c.Key, Total = c.Sum(t => t.Total)})
            .ToList();

现在它返回这个

[{"Day":3,"Total":9999.00},{"Day":4,"Total":9999.00},{"Day":5,"Total":9999.00}]

但我想要一个结果

{"Day":[3,4,5], "Total":[9999, 9999, 9999]}

这个结果更容易绘制图表。

谢谢你们

4

2 回答 2

4
var groups = _uow.Orders.GetAll()
            .Where(x => x.Created > baselineDate)
            .GroupBy(x => x.Created.Day);

var orders = new {
    Day = groups.Select(g => g.Key).ToArray(),
    Total = groups.Select(g => g.Sum(t => t.Toal)).ToArray()
};
于 2013-07-04T17:54:22.370 回答
0

我没试过,但可能是这样的:

Orders[] orders = (your query).ToArray();
于 2013-07-04T17:54:16.323 回答