LINQ to Entities Does Not Recognize "System.String ToString ()" Method

string[] userIds = userList.Split(','); // is an array of integers IList<User> users = (from user in this.repository.Users where userIds.Contains(user.Id.ToString()) select user).ToList(); 

the above query gives

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

What can I do?

+8
linq-to-entities
Nov 08 '10 at 7:01
source share
2 answers

Avoid calling ToString . You want something like this:

 userIds.Contains(user.Id) 

To do this, the userIds list must be a collection of the type that user.Id has. If you need integers, use int.Parse to convert strings to integers:

 int[] userIds = userList.Split(',').Select(s => int.Parse(s)).ToArray(); 
+7
Nov 08 2018-10-11T00:
source share

use may use something like this,

 where userIds.Contains(SqlFunctions.StringConvert((double)user.Id)) 

instead of where userIds.Contains(user.Id.ToString())

it should work

+13
Oct 28 2018-11-28T00:
source share



All Articles