LINQ

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

Yukarıdaki sorgu LINQ

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

Ne yapabilirim

verir?

cevap

7

ToString numaralı çağrıdan kaçının.

userIds.Contains(user.Id) 

user.Id sahip türde bir koleksiyon olmalıdır bu esere listesini userIds yapmak için: Böyle bir şey istiyorum. Eğer tamsayılar istiyorsanız tamsayılar için dizeleri dönüştürmek için int.Parse kullanın:

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

kullanımı böyle bir şey kullanabilirsiniz

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

yerine where userIds.Contains(user.Id.ToString())

bu

çalışması gerekir