I have a database with content, designed to be very generic. One of the columns is MetaTag1, of type nvarchar(255), which contains dates in string format. I can't change this to DateTime type. I use Entity Framework code first to query the table with LINQ.
Now I have to do something like:
var dateAsString = "12/04/2015";
var result = context.MetaTags.Where(mt => DateTime.Parse(dateAsString) > DateTime.Parse(mt.MetaTag1));
This doesn't work, as I get the exception:
'LINQ to Entities does not recognize the method 'System.DateTime Parse(System.String)' method, and this method cannot be translated into a store expression.'
One solution would be to first materialize the results in memory with ToList() and do the filtering in LINQ to entities. But this means that all results have to be retrieved first.
Is there another way to compare strings as dates in LINQ?
Thanks!