代码之家  ›  专栏  ›  技术社区  ›  stpdevi

如何在实体框架中查找月份之间的数据?

  •  0
  • stpdevi  · 技术社区  · 10 年前

    我需要显示本月的数据(从月开始到月结束的数据) 我知道如何在MySQL中进行以下查询

    enter code here select  @MonthAmount := IFNULL(sum(AmountReceived), 0.0) as TotoalAmountperMonth  
        from collection 
        where  date_time between DATE_FORMAT(NOW() ,'%Y-%m-01') 
            and LAST_DAY(now() - interval 0 month ) and AgentID=v_agent) as monthamount
    

    但如何使用实体(lambda表达式),当我在谷歌上搜索到今天但在一个月内得到的数据时,我对实体是陌生的?

    下面的查询得到了今天数据的结果

    enter code here  var newAuctionsResults = repo.FindAllAuctions()
                        .Where(a => a.IsActive == true 
                                    || (a.StartTime.Value.Year == todayYear
                                        && a.StartTime.Value.Month == todayMonth
                                        && a.StartTime.Value.Day == todayDay))
                        .ToList();
    
    1 回复  |  直到 10 年前
        1
  •  4
  •   user3559349 user3559349    10 年前

    尝试

    DateTime date = DateTime.Today;
    var newAuctionsResults = repo.FindAllAuctions()
      .Where(a => a.StartTime.Value.Year == date.Year 
        && a.StartTime.Value.Month == date.Month)