如何在entityframework中查找月份之间的数据?

时间:2014-07-14 10:15:26

标签: asp.net-mvc entity-framework-5

我要求显示本月的数据(月份开始结束数据) 我知道如何在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 个答案:

答案 0 :(得分:1)

尝试

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