我正试图通过Linq查询从第一个块到第二个块,这可能吗?
Year Quarter WordDoc SpreadSheet
---------------------------------------------------
2005 Q1 q1file.doc -
2005 Q1 - q1file.xls
2005 Q2 q2file.doc -
2005 Q2 - q2File.xls
2005 Q3 q3file.doc -
2005 Q3 - q3File.xls
2006 Q4 q4file.doc -
2006 Q4 - q4File.xls
第二块:
Year Quarter WordDoc SpreadSheet
---------------------------------------------------
2005
Q1 q1file.doc q1File.xls
Q2 q2file.doc q2File.xls
Q3 q3file.doc q3File.xls
2006
Q4 q4file.doc q4File.xls
不幸的是,我到目前为止所能解决的是按年份分组:
var results =
from entry in SampleDeals
group entry by entry.Year into years
select years;
results.Dump();
答案 0 :(得分:0)
假设所有组都有2个元素,一个用word文档,另一个用电子表格
var groups = SampleDeals.GroupBy(deal => new {Year = deal.Year, Quarter = deal.Quarter});
var whatYouWant = groups.Select(group => new {Year = group.Year, Quarter = group.Quarter,
WordDoc = group.First().WordDoc ?? group.ElementAt(1).WordDoc,
SpreadSheet = group.First().SpreadSheet ?? group.ElementAt(1).SpreadSheet});