LINQ-To-SQL OrderBy with DateTime Not Working
.net, c#, linq-to-sql
Solution
Try evaluating the expression without sorting, and then apply the sort to the results of Distinct:
(Linq-To-Sql-Expression).Distinct().OrderByDescending(x => x.TIMECARDDATE).ToList()
Problem
I have this LINQ query. The date is stored as a string in the database, but I need to order by it. So I convert it to a DateTime, but it doesn't order. ``` (from m in dbDataContext.TimeCards where m.TIMECARDDATE != "" && m.TIMECARDDATE != null orderby Convert.ToDateTime(m.TIMECARDDATE) descending select Convert.ToDateTime(m.TIMECARDDATE)).Distinct().ToList(); ``` Any idea why it doesn't work? I can't change the database, so I have to deal with the data the way it is. I get the data back ordered like this... ``` 2/27/2009 2/26/2009 2/25/2009 2/28/2009 2/24/2009 ```