1

I am using Entity Framework, and I have a line of code that convert string field (id)to int and compare with a number

 students = students.Where(s => (Int32.Parse( s.id)>5555));

Whenever I try to run it I receive rhis error. "LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression."

I have tried seveal different things and nothing is working, so any help would be great.

6
  • 1
    Did you try Convert.ToInt32 ? Commented May 9, 2015 at 5:16
  • yes.it didnt work.and caused that error Commented May 9, 2015 at 5:23
  • Try this Int32.TryParse Commented May 9, 2015 at 5:24
  • If your model.id have db type int, why you even need to to parse it to int in linq2entities? I think you should repair your model and not cast at all Commented May 9, 2015 at 5:26
  • 2
    possible duplicate of Entity Framework/Linq EXpression converting from string to int Commented May 9, 2015 at 5:27

1 Answer 1

5

Firstly I would highly recommend against converting the column into an int, you lose the indexing on the column. You rather convert the int into a string. However here is how to fix your code.

  1. Firstly sign the Contributor License Agreement.
  2. Then you fork the Entity Framework git repo.
  3. Write a new MethodCallTranslator.CallTranslator which will take Convert.ToInt32(string) and replace it with (int) string.
  4. Register the new MethodCallTranslator.CallTranslator within MethodCallTranslator.
  5. Write unit tests for your test case.
  6. Check in
  7. Create Pull Request
  8. Wait
  9. Download new version of Entity Framework from nuget
Sign up to request clarification or add additional context in comments.

1 Comment

Great step by step tutorial, +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.