8
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?

2 Answers 2

14

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

Sign up to request clarification or add additional context in comments.

Comments

7

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.