Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
707 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...