Click here to Skip to main content
14,236,520 members
Rate this:
Please Sign up or sign in to vote.
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.
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

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
            })
            .ToList<Practices>();
   
v2
Comments
AmitGajjar 31-Aug-12 8:41am
   
Correct. 5+
chowdary2005 31-Aug-12 9:53am
   
It is showing error.
Dylan Morley 31-Aug-12 10:02am
   
What is the error?
Rate this:
Please Sign up or sign in to vote.

Solution 1

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
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Hi,

Please have a look @ this Discussion[^]

Thanks
-Amit Gajjar
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100