帮助Tricky Linq Group按时间段 [英] Help with Tricky Linq Group by for time ranges
问题描述
我有一个班级,表示员工可以工作的班次:
public class Shift {
public int Id {get; set;}
public DateTime Start {get; set;}
public DateTime End {get; set;}
public DayOfWeek Day {get;设置;}
}
并且说我有单个员工的这些班次的列表:
列表< Shift> myShifts;
我知道我可以通过以下linq语句来一天班进行组:
var shiftingByDay = from a in myShift
group a by a.Day;
我的问题:每天,如何获得重叠的所有班次,单独的组,不重复计数?
重叠移位是开始或结束时间与另一个班次开始或结束时间重叠的位置。 >
如果可能,我希望能够使用linq。
尝试这样:
http://staceyw.spaces.live.com/Blog/cns!F4A38E96E598161E!993.entry
I have a class that represents a shift that employee's can work:
public class Shift {
public int Id { get; set;}
public DateTime Start {get;set;}
public DateTime End { get; set;}
public DayOfWeek Day { get; set;}
}
And say I have a list of these shifts for a single employee:
List<Shift> myShifts;
I know I can get group the shifts by day with the following linq statement:
var shiftsByDay = from a in myShift
group a by a.Day;
My question: For each day, how can I get all the shifts that overlap, in separate groups, without double counting?
An overlapping shift is one where either the start or end times overlap with another shifts start or end times.
I'd love to be able to do this with linq if at all possible.
Try this:
http://staceyw.spaces.live.com/Blog/cns!F4A38E96E598161E!993.entry
这篇关于帮助Tricky Linq Group按时间段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!