In Table, DueDate data type is varchar. Now I want to check the due date with today\'s date
var query = (from o in db.Order_Reports
where Convert.
The problem is that Linq-to-Entities is not capable of turning Convert.ToDateTime
into valid sql. If you bring all the records into memory with a call to AsEnumerable()
or ToList()
then you will be using Linq-To-Sql and that will work with C# functions:
var query = (from o in db.Order_Reports.AsEnumerable()
where DateTime.ParseExact(o.ReportDueDateTime,
"MM/dd/yyyy",
"M/d/yyyy") >= DateTime.Now
select o);
The problem with that is that you might be bringing too many records into memory. But if you have enough reports for that to be a worry, then you should probably be putting a database index on that ReportDueDateTime
and you need that index to be in date order. So change that column to a DateTime
or change the data into a format that can be sorted alphabetically - like "YYYY-MM-DD-HH-mm". Then you could do this:
var query = (from o in db.Order_Reports
where String.Compare(ReportDueDateTime,
DateTime.Now.ToString("YYYY-MM-DD-HH-mm")) >= 0
select o);