LINQ to Entities 无法识别 'Int32 Parse(System.String)' 方法,
LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method,
我正在使用 Entity Framework,我有一行代码将字符串字段 (id) 转换为 int 并与数字进行比较
students = students.Where(s => (Int32.Parse( s.id)>5555));
每当我尝试 运行 它时,我都会收到 rhis 错误。 "LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression."
我已经尝试了几个不同的东西,但没有任何效果,所以任何帮助都会很棒。
首先,我强烈建议不要将列转换为 int,否则会丢失列上的索引。您宁愿将 int 转换为字符串。然而,这是修复代码的方法。
- 先签Contributor License Agreement。
- 那你fork the Entity Framework git repo.
- 写一个新的
MethodCallTranslator.CallTranslator
,它将 Convert.ToInt32(string)
替换为 (int) string
。
- 在
MethodCallTranslator
内注册新的 MethodCallTranslator.CallTranslator
。
- 为您的测试用例编写单元测试。
- 签到
- 创建拉取请求
- 等等
- 从 nuget
下载新版本 Entity Framework
我正在使用 Entity Framework,我有一行代码将字符串字段 (id) 转换为 int 并与数字进行比较
students = students.Where(s => (Int32.Parse( s.id)>5555));
每当我尝试 运行 它时,我都会收到 rhis 错误。 "LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression."
我已经尝试了几个不同的东西,但没有任何效果,所以任何帮助都会很棒。
首先,我强烈建议不要将列转换为 int,否则会丢失列上的索引。您宁愿将 int 转换为字符串。然而,这是修复代码的方法。
- 先签Contributor License Agreement。
- 那你fork the Entity Framework git repo.
- 写一个新的
MethodCallTranslator.CallTranslator
,它将Convert.ToInt32(string)
替换为(int) string
。 - 在
MethodCallTranslator
内注册新的MethodCallTranslator.CallTranslator
。 - 为您的测试用例编写单元测试。
- 签到
- 创建拉取请求
- 等等
- 从 nuget 下载新版本 Entity Framework