我有以下类结构:
public class TaskLog
{
public DateTime LogDate { get; set; }
public string Robot { get; set; }
public string Task { get; set; }
public Enums.ProbeDataState State { get; set; }
public TaskLog()
{
}
}
我创建了一个通用列表,如下所示:
List<TaskLog> Logs;
我的输出:
Robot Date State
---------------------------------------------
aaa 8/5/2013 12:00:00 AM Task:1=fileDeltaFailed
aaa 8/5/2013 12:00:00 AM Task:2=fileDeltaFailed
aaa 8/5/2013 12:00:00 AM Task:4=fileDeltaFailed
bbb 8/5/2013 12:00:00 AM Task:1=fileDeltaFailed
bbb 8/5/2013 12:00:00 AM Task:2=fileDeltaFailed
bbb 8/5/2013 12:00:00 AM Task:4=fileDeltaFailed
但是,我想将任务和状态分组如下:
Tasks
Robot Date 1 2 4
aaa 8/5/2013 12:00:00 AM fileDeltaFailed fileDeltaFailed fileDeltaFailed
bbb 8/5/2013 12:00:00 AM fileDeltaFailed fileDeltaFailed fileDeltaFailed
我尝试使用 groupby 没有运气,并且非常卡住。
例如
var dataQuery = Logs.Where(w => w.LogDate >= start && w.LogDate <= finish).GroupBy(g => g.LogDate).Select(t => new
{
LogDate = t.Key,
Details = t.OrderBy(o => o.Robot)
}).ToList();