我正在尝试创建一个 linq 查询,该查询将产生一个日期范围的集合,其中包含容量值的总和,同时考虑到范围可以重叠,我想要一个总和和一个重叠期间的不同日期范围。谢谢。
public ActionResult Index()
{
List<Capacities> _list = new List<Capacities>{
new Capacities {StartDate = DateTime.Parse("01/01/2013"), StopDate = DateTime.Parse("01/01/2013 06:00"), Capacity = 100},
new Capacities {StartDate = DateTime.Parse("01/01/2013 04:00"), StopDate = DateTime.Parse("01/02/2013 00:00"), Capacity = 120},
new Capacities {StartDate = DateTime.Parse("01/04/2013"), StopDate = DateTime.Parse("01/04/2013 15:00"), Capacity = 100},
new Capacities {StartDate = DateTime.Parse("01/04/2013 15:00"), StopDate = DateTime.Parse("01/04/2013 18:00"), Capacity = 150}
};
//results expected
//01/01/2013 00:00 - 01/01/2013 04:00 100
//01/01/2013 04:00 - 01/01/2013 06:00 220
//01/01/2013 06:00 - 01/02/2013 00:00 120
//01/04/2013 00:00 - 01/04/2013 15:00 100
//01/04/2013 15:00 - 01/04/2013 18:00 150
return View();
}
public class Capacities
{
public DateTime StartDate { get; set; }
public DateTime StopDate { get; set; }
public int Capacity {get;set;}
}