嗨,我正在尝试找出给定年份和月份的每个月的上半月和下半月如何将项目分组?
IE
比如说我必须在每个月的 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
我将如何拆分它,所以我想在一年/一个月内将航班按两周分组
IE
2012 年 7 月第 1 周和第 2 周的航班
2012 年 7 月第 3 周和第 4 周的航班
所以这就是我到目前为止所拥有的......最终它必须是某种使用自动映射器的视图模型等我还不确定它是如何将它巧妙地融入某种 ViewModel 形式......
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 }
}
}
};