문제

In my table there is a varchar field which contains dates. (That's how SAP stores dates) Anyway to run a query against this field similar to:

from c in db.Set<MyTable>()
   where c.Date >= "20120921" && c.Date <= "20121021"
   select c

I tried to do a String.Compare, but EF can't translate that to sql.

where Stirng.Compare(c.Date, "20120921") >= 0

I also tried to convert both strings to int and do the comparison, and again EF doesn't support that.

도움이 되었습니까?

해결책

You can try using SqlFunctions.DateDiff method overload that takes three strings, like this:

var res = from c in db.Set<MyTable>()
   where SqlFunctions.DateDiff("dd", c.Date, "20120921") >= 0
      && SqlFunctions.DateDiff("dd", c.Date, "20121021") < 0
   select c
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top