问题
When running a raw linq statement against entities with entity framework 5 - db2400 database, this where clause is rendered as good SQL and executes as needed:
where entity.Number == stringNumber && entity.EffectiveDate == effectiveDate
Rendered SQL Clause:
WHERE (Filter1.NUMBER = @p__linq__0) AND (Filter1.EFFECTIVE_DATE = @p__linq__1)}
However, when dynamically generating an expression with this same DateTime comparison, the SQL is sent to the DB2400 as a string casted timestamp. And DB2 says, "I cannot compare a timestamp and a Date!" (since the column is of type Date on the table).
Rendered Expression:
Entity => ((Entity.Number == "somestring") And (Entity.EffectiveDate == 10/1/2012 12:00:00 AM))
Rendered SQL:
WHERE (('someString' = Extent1.NUMBER)) AND (CAST('2012-10-01 00:00:00.00000' AS timestamp) = Extent6.EFFECTIVE_DATE)}
How is this DateTime expression built?
Expression.Equal(Property, DateTime.Parse(someDateTime.ToString()));
来源:https://stackoverflow.com/questions/21048053/dynamic-expression-casting-datetime-as-timestamp