0
您好,我正在努力研究如何将物品分组到每个月的第一个和第二个半月以获得特定的年份和月份?c#linq组由两周或x天数?
即
例如说我必须列出在每月6日,每月15日项的名称。
说,比如我有
Flight Name Flight Date
Flight 1 01/07/2012
Flight 2 12/07/2012
Flight 3 18/07/2012
Flight 4 28/07/2012
我怎么会拆呢,所以我想在一年内由两星期组航班/月
即
的航班,每周七月1和2 - 2012年
7月第3周的航班和4 - 2012
所以这是我迄今为止.. 最终还是必须要使用某种视图模型的automapper等我不知道作为然而它会如何获取整齐地变成某种形式的视图模型的...
var flightEntities = from f in flightsAsViewModels
select new
{
YearGroups = from flightYearGroup in context.Flights
group flightYearGroup by flightYearGroup.FlightDateTime.Year
into yearGroup
orderby yearGroup.Key descending
select new
{
Year = yearGroup.Key,
MonthGroups = from flightMonthGroup in yearGroup
group flightMonthGroup by flightMonthGroup.FlightDateTime.Month
into monthGroup
orderby monthGroup.Key ascending
select new {
Month = monthGroup.Key,
HalfMonthGroups = from months in monthGroup
group months by (months.FlightDateTime.Day <= 15 ? 1 : 2) into splitMonthFlights
orderby splitMonthFlights.Key
select new { WhichHalfOfMonth = splitMonthFlights.Key, Flights = splitMonthFlights }
}
}
};
第5周呢?几乎每个月都有超过4周的时间。 –
这是在LINQ to SQL(等)或LINQ to Objects? (LINQ to Objects会使它简单得多......) –
@JonSkeet:根据标签,它是LINQ到SQL –