美文网首页.NET
LINQ 查询本月本周数据、趋势图

LINQ 查询本月本周数据、趋势图

作者: 老中医167788 | 来源:发表于2022-08-04 11:48 被阅读0次

    本周

    (n => n.date > DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.Date.DayOfWeek))) 
    

    重点说明: DateTime.Now.Date.DayOfWeek返回当前星期几

    本月

    (n => n.date > DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.Date.Day))) 
    

    完整代码演示

        /// <summary>
        /// 管理后台首页-订单卡片 数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<GetCardOrderDataResponse> GetCardOrderData()
        {
            var yesterdayU = _businessAuditLogRepository.NoTrackingEntities
                .Where(x => x.Type == BusinessAuditLogType.Unpackbox.TryToInt())
                .Take(7)
                .OrderByDescending(x => x.Id)
                .AsEnumerable()
                .Where(x => x.CreateTime.Date == DateTime.Now.AddDays(-1).Date)
                .Count();
            var todayU= _businessAuditLogRepository.NoTrackingEntities
                .Where(x => x.Type == BusinessAuditLogType.Unpackbox.TryToInt())
                .Take(7)
                .OrderByDescending(x => x.Id)
                .Where(x => x.CreateTime.Date == DateTime.Today.Date)
                .Count();
    
           var yesterdayS = _businessAuditLogRepository.NoTrackingEntities
                .Where(x => x.Type == BusinessAuditLogType.StoringPackage.TryToInt())
                .Take(7)
                .OrderByDescending(x => x.Id)
                .AsEnumerable()
                .Where(x => x.CreateTime.Date== DateTime.Now.AddDays(-1).Date)
                .Count();
            var todayS = _businessAuditLogRepository.NoTrackingEntities
                .Where(x => x.Type == BusinessAuditLogType.StoringPackage.TryToInt())
                .Take(7)
                .OrderByDescending(x => x.Id)
                .AsEnumerable()
                .Where(x => x.CreateTime.Date == DateTime.Now.Date)
                .Count();
            return await Task.FromResult(new GetCardOrderDataResponse()
            {
                TodayStoring = todayS,
                TodayUnpack = todayU,
                YesterdayStoring = yesterdayS,
                YesterdayUnpack = yesterdayU
            });
        }
    

    相关文章

      网友评论

        本文标题:LINQ 查询本月本周数据、趋势图

        本文链接:https://www.haomeiwen.com/subject/hryywrtx.html