I have a date stored as a string in a not so good format (dd-MM-yyyy). The SQL server cannot automatically convert this into a date, at least not with the settings that are on it, but with a little help it fixes it. The following SQL statement works perfectly:
select * from table
where convert(date,myValue,105) < GETDATE()
Problem I have is, how do I do this in LINQ? I tried different things manually and I tested Linqer to generate LINQ from my SQL. This is what Linqer gives me:
from table in db.table
where
Convert.ToDateTime(myValue) < DateTime.Now
select new {
...
}
Problem is, when I run the statement above I get:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
Probably because it drops the 105 parameter to the convert method. I've tried different parse methods (Parse, ParseExact and Convert.ToDateTime with an IFormatProvider) but all those give me errors that are more or less like:
Method 'System.DateTime ParseExact(System.String, System.String, System.IFormatProvider)' has no supported translation to SQL.
So my question is, is there a good way to convert a date with an "odd" dateformat in Linq so that I will get working T-SQL? I already have a "working" solution, but I would like to know if there's any way to get Linq to interpret this in a nice way?