linq:检查某个表中是否有同一天或同一周的条目

本文关键字:同一天 一周 是否 检查 linq | 更新日期: 2023-09-27 18:27:48

所以我想做的是获取数据库中来自选定日期和该日期所在周的条目数。数据库列和我的变量都是日期时间字段。我的日期方法是:

private int multiUse_timesInADay()
    {
           daydate date = currentDate.date;
        var submitCount = from campaignMessages in dcCRData.Mytable
                          where  campaignMessages.Created == date 
                          select campaignMessages;
        int count = submitCount.Count();
        return count;
    }

我有点不知道如何进行周搜索。有什么想法吗?

linq:检查某个表中是否有同一天或同一周的条目

//first get to the last monday i.e. start of the week
int delta = DayOfWeek.Monday - currentDate.date.DayOfWeek;
DateTime monday = currentDate.date.AddDays(delta);

var submitCount = from campaignMessages in dcCRData.Mytable
                  where  campaignMessages.Created >= monday &&  campaignMessages.Created <= monday.AddDays(7)    
                  select campaignMessages;