Tricky Linq Group通过时间范围 [英] Tricky Linq Group by for time ranges

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

问题描述

我有一个班级代表员工可以进行的工作:

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;

我知道我可以使用以下linq语句按日分组:

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;

我的问题:如何每天获取重叠的所有班次?

重叠的班次是指开始或结束时间与另一个班次的开始或结束时间重叠。

An overlapping shift is one where either the start or end times overlap with another shifts start or end times.

如果可能的话,我希望能够使用linq做到这一点。

I'd love to be able to do this with linq if at all possible.

推荐答案

尝试一下:

http://staceyw.spaces.live.com/Blog/cns!F4A38E96E598161E!993.entry

这篇关于Tricky Linq Group通过时间范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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