2008-10-18 11 views

답변

29

where 절에서 이야기하고 있다고 가정합니다. 이것은 기본적으로 두 DateTime 객체를 다른 곳에서 비교하는 것과 같습니다.

using (DataContext context = new DataContext()) { 
    var query = from t in context.table 
       where t.CreateDate.Date < DateTime.Today.AddMonths(-1) 
       select t; 
} 
5

그냥 LINQ To Entities에 추가하면 변수와 비교해야합니다. 예 : 원하지 않는 경우

 DateTime lastMonth = DateTime.Today.AddMonths(-1); 
     using (var db = new MyEntities()) 
     { 
      var query = from s in db.ViewOrTable 
         orderby s.ColName 
         where (s.StartDate > lastMonth) 
         select s; 

      _dsResults = query.ToList(); 
     } 
0

코드는

LINQ to Entities does not recognize the method 'System.DateTime AddYears(Int32)' method, and this method cannot be translated into a store expression. 

내가 DbFunctions.AddYears을 사용하는 것이 좋습니다 것입니다 던져. 당신은 단지 날짜가 아닌 시간에 대해 우려하는 경우 또한, 당신은 this-

DbFunctions.TruncateTime(x.date) == 
DbFunctions.TruncateTime(DbFunctions.AddYears(DateTime.Today, 1)) 
같은 DbFunctions.TruncateTime

뭔가를 사용할 수 있습니다

관련 문제