こんにちは、特定の年と月の各月の前半と後半にアイテムをグループ化する方法を考え出そうとしていますか?
すなわち
たとえば、毎月 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 年/1 か月以内に 2 週間ごとにフライトをグループ化したいので、どのように分割しますか?
すなわち
2012 年 7 月第 1 週および第 2 週のフライト
2012 年 7 月第 3 週と第 4 週のフライト
これは私がこれまでに持っているものです..最終的には、オートマッパーなどを使用したある種のビューモデルでなければなりません.
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 }
}
}
};