我正在使用 Entity Framework,我有一行代码将字符串字段 (id) 转换为 int 并与数字进行比较
students = students.Where(s => (Int32.Parse( s.id)>5555));
每当我尝试运行它时,我都会收到 rhis 错误。 “LINQ to Entities 无法识别‘Int32 Parse(System.String)’方法,并且无法将此方法转换为存储表达式。”
我已经尝试了几个不同的东西,但没有任何效果,所以任何帮助都会很棒。
最佳答案
首先,我强烈建议不要将列转换为 int,否则会丢失列上的索引。您宁愿将 int 转换为字符串。然而,这里是如何修复您的代码。
- 首先签署Contributor License Agreement .
- 那你fork the Entity Framework git repo .
- 写一个新的
MethodCallTranslator.CallTranslator
这需要Convert.ToInt32(string)
并将其替换为(int) string
. - 注册新
MethodCallTranslator.CallTranslator
在MethodCallTranslator
内. - 为您的测试用例编写单元测试。
- 签到
- 创建拉取请求
- 等等
- 从 nuget 下载新版本的 Entity Framework
关于c# - LINQ to Entities 无法识别方法 'Int32 Parse(System.String)' 方法,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30136302/