获取每周LINQ到SQL的谷歌图表

本文关键字:谷歌 SQL 每周 LINQ 获取 | 更新日期: 2023-09-27 18:02:49

我有一个问题,我不能过去,这是我的控制器报告-

    var week = DateTime.Now.Date.AddDays(-7);                   
    List<LeaveChartVM> data = new List<LeaveChartVM>();
    using (ApplicationDbContext db = new ApplicationDbContext())
    {        
        data = ( from u in db.UserProfiles
                select new LeaveChartVM
                {
                Users = (from up in db.UserProfiles
                         select up).Count(),
                OnLeaveToday = (from tol in db.CalendarData
                                where (today >= tol.StartTime && today <= tol.EndTime)
                                select tol).Count(),                                    
                SickLeave = (from sl in db.CalendarData
                             where sl.LeaveType == "5"
                             select sl).Count(),
                AnnualLeave = (from al in db.CalendarData
                               where al.LeaveType == "1"
                               select al).Count()
            }).Distinct().ToList();
    }

谁能帮我只返回这周的数据吗?我今天请假回来了,但我想创建一个折线图,返回本周的数据。

添加到这个信息不是很好,这里是calendardata的表结构-

[Subject]
  ,[Description]
  ,[StartTime]
  ,[EndTime]
  ,[AllDay]
  ,[Recurrence]
  ,[RecurrenceRule]
  ,[LeaveType]
  ,[StartTimeZone]
  ,[EndTimeZone]
  ,[UserId]
  ,[EventStatus]
  ,[ApporovedId]
  ,[ApprovedDate]
  ,[Duration]
  ,[EventAction]
  ,[EventDate]
  ,[uid]
  ,[colourId]
  ,[UserProfiles_Id]

和UserProfiles -

[Forenames]
  ,[Surnames]
  ,[Fullname]
  ,[EmployementType]
  ,[Displayname]
  ,[TeamId]
  ,[ShiftPatternId]
  ,[DepartmentId]
  ,[DateJoined]
  ,[DivsionId]
  ,[WindowsUser]
  ,[DateCreated]
  ,[DateOfAction]
  ,[ActionId]
  ,[Division_Id]

我想要返回的是在过去7个工作日和今天休年假和病假的人。

获取每周LINQ到SQL的谷歌图表

类似以下内容?

DateTime today = DateTime.Now.Date;
DateTime oneWeekAgo = today.AddDays(-7);
// usage
OnLeaveThisWeek = 
    (from tol in db.CalendarData
     where (tol.StartTime >= oneWeekAgo && tol.EndTime <= today)
     select tol).Count()

确保您的todayoneWeekAgo值符合您需要的逻辑,即是否包含今天,等等