LINQ到实体无法识别方法“的Int32解析(System.String)”的方法, [英] LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method,
问题描述
我使用实体框架,我有一个代码行转换成字符串字段(ID)为int并与多家比较
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));
每当我尝试运行它,我收到rhis错误。 LINQ到实体无法识别方法的Int32解析(System.String)的方法,而这种方法不能被翻译成店的表情。
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."
我曾尝试seveal不同的东西,并没有什么工作,所以任何帮助将是巨大的。
I have tried seveal different things and nothing is working, so any help would be great.
推荐答案
首先,我会强烈建议对列转换成一个int,你失去的列索引。你宁可INT转换为字符串。不过这里是如何解决你的代码。
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.
- 首先签署的贡献者许可协议。
- 然后你叉实体框架混帐回购协议一>
- 写一个新的
MethodCallTranslator.CallTranslator
将于Convert.ToInt32(串)
和(INT)字符串
。 - 注册新的
MethodCallTranslator.CallTranslator
在MethodCallTranslator
。 - 编写单元测试的测试用例。
- 检查
- 创建pull请求
- 等待
- 下载从的NuGet实体框架的新版本
- Firstly sign the Contributor License Agreement.
- Then you fork the Entity Framework git repo.
- Write a new
MethodCallTranslator.CallTranslator
which will takeConvert.ToInt32(string)
and replace it with(int) string
. - Register the new
MethodCallTranslator.CallTranslator
withinMethodCallTranslator
. - Write unit tests for your test case.
- Check in
- Create Pull Request
- Wait
- Download new version of Entity Framework from nuget
这篇关于LINQ到实体无法识别方法“的Int32解析(System.String)”的方法,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!