Click here to Skip to main content
15,437,002 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am trying to fetch some values from a table called practices using Linq to Entities.

Practices table contains the following.

PracticeID AutoIncrement,
PracticeName nvarchar(10),

now i need to get 3 practices from this list.
stirng [] pras = new string [] {"1", "3", "5"}

 AuthenticationEntities authEntity = new AuthenticationEntities();

                    List<practices> prac = (from p in authEntity.Practices
                                            where pras.Contains(p.PracticeID.ToString())
                                            select new Practices
                                                Practice = p.PracticeName

But it is showing as error

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

Kindly help.
Updated 31-Aug-12 2:29am

Why not declare the array as int type (or whatever numeric type the field is defined as)?

int [] pras = new int[] {1, 3, 5};

var authEntity = new AuthenticationEntities();

var prac = (from p in authEntity.Practices
            where pras.Contains(p.PracticeID)
            select new Practices
                Practice = p.PracticeName
Share this answer
AmitGajjar 31-Aug-12 8:41am    
Correct. 5+
Charles Shob 31-Aug-12 9:53am    
It is showing error.
Dylan Morley 31-Aug-12 10:02am    
What is the error?

see the below example.[^]

you can find the text using contains.
here your PracticeID is Integer and you are comparing it with string so there is casting problem.
i think you can`t do casting like this
i suggest use stored procedure for this.

Viprat Shah
Share this answer

Please have a look @ this Discussion[^]

-Amit Gajjar
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900