I have a method which accepts an ObjectQuery and adds Where clauses to it depending on whether it receives values for various filter parameters. The method has to return an ObjectQuery. How can i do a basic Date comparison e.g. where dateX < dateY.
This is my current code:
if (myDateFilter != null)
{
query = query.Where(
string.Format(
"it.ExpireDate < cast('{0}' as System.DateTime)",
myDateFilter));
}
With myDateFilter having a value of DateTime.Now, this code says: System.Data.SqlClient.SqlException: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
All the other paramaters are string or integer filters so weren't a problem to implement. Any ideas??