我现实生活中的例子太晦涩无法解释,但这是我正在尝试做的一个很好的近似......
Month
表有列:Id
,Name
Holiday
表有列:Id
, MonthId
, DayOfMonth
,Name
Appointment
表有列:Id
, MonthId
, DayOfMonth
,Description
如何生成按月份和日期排序的独特事件(假期和约会)列表?
样本结果:
Month Holiday Day Appointment Day
----------------------------------------
Nov Fly to NYC 25
Nov T-Giving 26
Nov Fly home 29
Dec Xmas 25
所以,我想要假期和事件的单独列,但我希望它们都是唯一的,并按月-日的顺序列出。
这是我到目前为止所拥有的(见内联评论):
var events =
from
m in GetMonths()
join
h in GetHolidays()
on m.Id equals h.MonthId
join
a in GetAppointments()
on m.Id equals a.MonthId
where
//something that narrows all combinations of events to only unique events
orderby
m.Id,
// something that interleaves h.DayOfMonth with m.DayOfMonth
select
new
{
Month = m.Name,
Holiday = h.Name,
HolidayDay = h.DayOfMonth,
Appointment = a.Description,
AppointmentDay = a.DayOfMonth
};