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

ऊपर क्वेरीLINQ विधि को नहीं पहचानता है '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

मैं क्या कर सकता देता है?

उत्तर

7

ToString पर कॉल से बचें।

userIds.Contains(user.Id) 

इस काम सूची userIds बनाने के प्रकार user.Id है जो का एक संग्रह होना चाहिए: आप कुछ इस तरह करना चाहते हैं। आप पूर्णांक चाहते हैं तो पूर्णांकों को तार कन्वर्ट करने के लिए int.Parse का उपयोग करें:

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

उपयोग कुछ इस तरह उपयोग कर सकते हैं,

where userIds.Contains(SqlFunctions.StringConvert((double)user.Id)) 
बजाय

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

इस

काम करना चाहिए
संबंधित मुद्दे