根據您的問題,這裏有一個例子類,將工作
public class FileStatus
{
public int? Id { get; set; }
public string Filename { get; set; }
public DateTime Date { get; set; }
public string Status { get; set; }
}
這裏是會得到你想要的結果的工作樣本,以便您可以將其傳遞到報告模板上:
var filedata= new List<FileStatus>()
{
new FileStatus(){ Id = 1, Filename = "file1", Date = new DateTime(2016,05,12,11,30,00), Status = "fail"},
new FileStatus(){ Id = 2, Filename = "file1", Date = new DateTime(2016,05,12,11,35,00), Status = "success"},
new FileStatus(){ Id = 3, Filename = "file2", Date = new DateTime(2016,05,13,12,01,00), Status = "success"},
new FileStatus(){ Id = 4, Filename = "file2", Date = new DateTime(2016,05,13,12,02,00), Status = "fail"},
new FileStatus(){ Id = 5, Filename = "file1", Date = new DateTime(2016,05,13,12,30,00), Status = "success"},
new FileStatus(){ Id = 6, Filename = "file3", Date = new DateTime(2016,05,13,12,31,00), Status = "fail"}
};
//remove the above and replace it with your own:
//IQueryable<FileData> filedata = this.context.FileData;
var result = filedata.GroupBy(c => new { c.Filename, c.Date.Date }).Select(c => new
{
Row = c.Key.Filename,
Column = c.Key.Date,
Value = filedata.FirstOrDefault(co => co.Id == c.Max(max => max.Id)).Status
}).OrderBy(c => c.Row).OrderBy(c => c.Column);
你介意分享你的第一部分進行的類,與你用來獲取數據的相關代碼沿樞軸表? – Svek
請分享課程和結構的代碼。你需要做的是數據透視,所以檢查細節http://linqlib.codeplex.com/wikipage?title=Pivot&referringTitle=Home – bhuvin
我需要這樣做的報告 –