I’ve got an error:
LINQ to Entities does not recognize the method ‘Int32 ToInt32(System.String)’ method, and this method cannot be translated into a store expression.
The piece of code:
plist= plist.Where(p => Convert.ToInt(p.Period) >= syslockPeriod);
p.Period example: 201206
pList is IQueryable. p.Period is string typed. sysLockPeriod is int.
How to fix it?
LINQ to entities will try to translate
Convert.ToInt32()into SQL instructions, because it’s not one of the known methods it can translate then it’ll generate that error.You have some workaround but for all of them you have to change your code. Let’s see what you can do (in order of preference, for me).
Periodproperty/field to the proper type. If it’s an integer type then why you store it in your DB as a string?IQueryabletoIListwithToList()beforeWhere(), now thewhereclause will be executed locally and not on the database (this may be something terrible to do if the list is pretty big).