Convert string to int in linq for objects in a large database

i wana convert string to int in linq for objects, but Convert.ToInt32 and int.Parse cannot translate to sql And my BIG database and cannot get all of them in memory (more than 60 thousand records and get more) my request looks like

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

error say cannot translate the conversion method

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

what's the solution

UPDATE: If there is no way to do this, please let me know about it, then I need to change the type of the field in the database, but it will be difficult :(

+3
source share
2 answers

, , < 1000 > 9999:

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

, stringYear . stringYear .

+3

, SQL

int myNumber = 1390;
var result = from dr in myEntitiy.TableX
             let num = myEntitiy.TableX.Take(1).Select(x => dr.stringYear).Cast<int>().FirstOrDefault()
             where num > myNumber
             select dr; 
+1

All Articles