LINQ中不能直接使用DateTime,否则会报错:‘The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are support’
需要把DateTime定义在LINQ之外,例如:
var now = DateTime.Now.Date; var query = from a in _workPeriodRepository.Table where a.StartDate <= now && a.EndDate >= now select a; return query.ToList();