'Error on converting string to datetime as part of Where condition [closed]

In my ling query I am trying to do like below

}).Where(r => r.dueDate == 
  DateTime.Parse(ConfigurationManager.AppSettings["1000"])).ToList()

But I am getting below error

LINQ to Entities does not recognize the method 'System.DateTime Parse(System.String)' method, and this method cannot be translated into a store expression

What should i do to avoid this ?



Solution 1:[1]

Like Martheen said:

var d = DateTime.Parse(ConfigurationManager.AppSettings["1000"])


...
}).Where(r => r.dueDate == d).ToList()

Even if it did work it's a waste of resource to parse a static date over and over again, one time for every item in the collection. If you have a million items, that's a million parses every time the query runs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Caius Jard