2010-11-08 10 views
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(); 

la consulta anterior daLINQ a Entidades no reconoce el método de método 'System.String ToString()'

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

¿Qué puedo hacer yo?

Respuesta

7

Evita la llamada al ToString. ¿Quieres algo como esto:

userIds.Contains(user.Id) 

para hacer este trabajo la lista userIds debe ser una colección del tipo que tiene user.Id. Si desea utilizar números enteros entonces int.Parse para convertir las cadenas en enteros:

int[] userIds = userList.Split(',').Select(s => int.Parse(s)).ToArray(); 
13

uso puede usar algo como esto,

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

en lugar de where userIds.Contains(user.Id.ToString())

esto debería funcionar

Cuestiones relacionadas