实例:搜索条件:2016年11月1号到10号的数据,

数据库中只有3号,6号,7号,8号,9号有数据,但是没有数据的也需要展示,数据可以显示为“-”。

DayList中的时间:["2016-11-03,2016-11-06,2016-11-07,2016-11-08,2016-11-09"]

开始时间: startTime;结束时间:endTime

//新建一个时间集合 左关联
List<TimeList> TimeList = new List<TimeList>();
//搜索时间小时差 DateTime.Now.ToShortDateString().ToString(); 

TimeSpan ts = endTime - startTime;
int Days = ts.Days;

//时间差,总共几天
for (int i = 0; i < Days+1; i++)
{
DateTime NewTime = startTime.AddDays(i);
TimeList.Add(new TimeList()
{
MONIDATE = NewTime
});
}
var dataT = (
from d in TimeList
join s in DayList on d.MONIDATE equals s.MONIDATE into temp
from tt in temp.DefaultIfEmpty()
select new
{
//基本信息
MONIDATE = (tt != null) ? tt.MONIDATE.ToString("yyyy-MM-dd") : d.MONIDATE.ToString("yyyy-MM-dd"),
Name= (tt != null) ? tt.Name: "-",
Age= (tt != null) ? tt.Age: "-"
});

 

public class TimeList

{

    public DateTime MONIDATE  { get; set; }

}

 如有好的办法,请大神多多指教!

相关文章:

  • 2022-01-18
  • 2021-07-06
猜你喜欢
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2022-02-08
  • 2021-06-12
  • 2021-09-23
  • 2021-12-05
相关资源
相似解决方案