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.

4

1 回答 1

5

首先,我强烈建议不要将列转换为 int,否则会丢失列上的索引。您宁愿将 int 转换为字符串。但是,这里是如何修复您的代码。

  1. 首先签署贡献者许可协议
  2. 然后你fork 实体框架 git repo
  3. 写一个新的MethodCallTranslator.CallTranslator,将Convert.ToInt32(string)它替换为(int) string.
  4. MethodCallTranslator.CallTranslatorMethodCallTranslator. _
  5. 为您的测试用例编写单元测试。
  6. 报到
  7. 创建拉取请求
  8. 等待
  9. 从 nuget 下载新版本的实体框架
于 2015-05-09T06:13:40.323 回答