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.
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.
- Firstly sign the Contributor License Agreement.
- Then you fork the Entity Framework git repo.
- Write a new
MethodCallTranslator.CallTranslator
which will takeConvert.ToInt32(string)
and replace it with(int) string
. - Register the new
MethodCallTranslator.CallTranslator
withinMethodCallTranslator
. - Write unit tests for your test case.
- Check in
- Create Pull Request
- Wait
- Download new version of Entity Framework from nuget
来源:https://stackoverflow.com/questions/30136302/linq-to-entities-does-not-recognize-the-method-int32-parsesystem-string-meth