LINQ to Entities does not recognize the method '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())
s开发者_如何学Pythonelect 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?
use can use something like this,
where userIds.Contains(SqlFunctions.StringConvert((double)user.Id))
instead of where userIds.Contains(user.Id.ToString())
this should work
Avoid the call to ToString
. You want something like this:
userIds.Contains(user.Id)
To make this work the list userIds
must be a collection of the type which user.Id
has. If you want integers then use int.Parse
to convert the strings to integers:
int[] userIds = userList.Split(',').Select(s => int.Parse(s)).ToArray();
精彩评论