帮助Tricky Linq Group按时间段 [英] Help with Tricky Linq Group by for time ranges

查看:235
本文介绍了帮助Tricky Linq Group按时间段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个班级,表示员工可以工作的班次:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆