LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method,

烈酒焚心 提交于 2019-11-28 06:28:53

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/30136302/linq-to-entities-does-not-recognize-the-method-int32-parsesystem-string-meth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!