将字符串转换为在LINQ诠释对大数据库实体 [英] Converting string to int in linq to entities on big database

查看:160
本文介绍了将字符串转换为在LINQ诠释对大数据库实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我瓦纳字符串转换在LINQ为int的实体,但Convert.ToInt32和int.Parse不能转换为SQL
和我的数据库是大,不能让所有的人都对内存(超过60K的记录,并得到大)
我的查询是一样的东西。

i wana convert string to int in linq to entities but Convert.ToInt32 and int.Parse can not translate to sql And my database is BIG and can not get all of them to memory (over 60k record and get bigger) my query is something like

int myNumber = 1390;
var result = from dr in myEntitiy.TableX
             where (Convert.ToInt32(dr.stringYear) > myNumber) // <== error
             select dr; 



错误说无法翻译转换方法

error say cannot translate convert method

LINQ到实体无法识别方法的Int32 ToInt32(System.String)的方法,而这种方法不能被翻译成店的表情。

LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression.

什么解决方案

更新:
如果没有办法做到这一点,请让我知道这个,然后我必须改变数据库字段类型,但将难以:(

UPDATE : If there is no way to do this please make me sure about this, then i have to change field type in database but it will be hard :(

推荐答案

我认为这是相当安全的做比较,因为串,除非你有几年< 1000> 9999

I think it is quite safe to do the comparison as string, unless you have years < 1000 or > 9999:

... dr.stringYear.CompareTo(myNumberString) > 0

这是好处是,在任何指数 stringYear 可能是在执行计划中使用。转换 stringYear 来数消除了任何索引。

An advantage would be that any index on stringYear may be usable in an execution plan. Converting stringYear to number eliminates any index.

这篇关于将字符串转换为在LINQ诠释对大数据库实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆