由时间段与整蛊的LINQ集团帮助 [英] Help with Tricky Linq Group by for time ranges

查看:138
本文介绍了由时间段与整蛊的LINQ集团帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代表一个转变,员工可以工作的类:

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

这篇关于由时间段与整蛊的LINQ集团帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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