我有兩個相關的一對多實體生成JSON結果基於兩個相關的entites
種族和汽車(在比賽中含有大量的汽車)
我需要生成一個JSON結果將它傳遞給jQGrid,我認爲可以這樣做,而不需要創建新的類女巫將包含屬性。我以爲我可以這樣做:
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = (from c in Races
select new
{
//c.Cars.Id.ToString(), - need iteration
cell = new string[] {
//c.Cars.Id.ToString(), - need iteration
c.Date.ToString(),
c.Type.ToString(),
c.Cars //But how i may loop all Cars colection here?
//c.Cars.Name - need iteration
//c.Cars.Speed - need iteration
}
}).ToArray()
};
但汽車屬性代表集合。我如何迭代集合初始值設定項內?或者我應該更好地創造女巫將包含我需要的所有屬性?
任何想法?
比方說汽車有性能名稱速度Id和種族有性能日期,類型
的數據將顯示這樣的:
Date | Type | Id | Name | Speed
02/03/2011 | A | 1 | MegaName1 | 130
02/03/2011 | A | 2 | MegaName2 | 112
02/03/2011 | A | 3 | MegaName3 | 132
03/05/2011 | B | 4 | MegaName2 | 112
03/05/2011 | B | 5 | MegaName4 | 33
怎麼辦你想在網格中表示這些信息?每一行都會代表一場比賽,而這些列又如何呢? –
@Darin Dimitrov問題更新,每一行代表比賽+車 – Joper