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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With