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:
Hello,

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),
etc.

now i need to get 3 practices from this list.
C#
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
                                            }).ToList<practices>();


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.
Posted
Updated 31-Aug-12 2:29am
v2

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

C#
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
            })
            .ToList<Practices>();
 
Share this answer
 
v2
Comments
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?
hi,

see the below example.

http://msdn.microsoft.com/en-us/vstudio/bb737939#strcont[^]

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.

Thanks,
Viprat Shah
 
Share this answer
 
Hi,

Please have a look @ this Discussion[^]

Thanks
-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