var now = DateTime.Now();
int weeknow = Convert.ToInt32(now.DayOfWeek);
//因为是以星期一为第一天,所以要判断weeknow等于0时,要向前推6天。
weeknow = (weeknow == 0 ? (7 - 1) : (weeknow - 1));
int daydiff = (-1) * weeknow;
//本周第一天
var weekfist = DateTime.Now.AddDays(daydiff);
var weeklast = weekfist.AddDays(7);
query =
query.Where(x => x.StartTime.Date >= weekfist.Date && x.EndTime.Date <= weeklast.Date);

04-16 01:04