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();

 

posted on 2013-07-13 18:24  Mr.Young  阅读(1306)  评论(0编辑  收藏  举报