2

Convert string to double using LINQ query and get data

data1 => string type
data2 => double type

Query :

var query = get to db
query= query.Where(W => double.Parse(W.data1) >= W.data2).ToList();

Error :

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

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
Hero
  • 53
  • 3
  • 8
  • 1
    https://stackoverflow.com/questions/41802366/get-result-function-in-linq-without-translate-to-store-expression/41802414#41802414 – Salah Akbari Oct 10 '17 at 14:06
  • 1
    Although your query is not about converting string to double! – Salah Akbari Oct 10 '17 at 14:06
  • 1
    The error is because LINQ is trying to transform double.Parse into a SQL expression (which doesn't exit's). see @S.Akbari link to see more details, on how you can filter in memory. – Jorge Oct 10 '17 at 14:07
  • 1
    I'd suggest looking at why you have a numerical value saved as a string in your DB. If possible I'd suggest fixing that. – juharr Oct 10 '17 at 14:09
  • As others have said, fix the schema. This isn't only about convenience, or avoiding a cast. Forcing such a conversion means that *no* indexes that cover `data1` can be used, forcing a full table scan. – Panagiotis Kanavos Oct 10 '17 at 14:13

0 Answers0