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

I am facing some problem while executing the query having 'Contains' keyword in Dynamic linq in C#. I am getting the below error

No property or field exists in type 'Int32'

My code is as below:

If I user the 'Contains' keyword for datatype string field, then it works fine as below

string[] CandidateNamesArray = new string[]{"Ram", "Venkat", "Micheal"}
var dynamicLinqQuery = Candidates.Where("CandidateName.Contains(@0)", CandidateNamesArray ); - works fine

But if I use the 'Contains' keyword for datatype int field, then it throws exception as below

int[] CandidateIdsArray = new int[]{4, 78, 101}
var dynamicLinqQuery = Candidates.Where("CandidateId.Contains(@0)", CandidateIdsArray);
Runtime Exception - "No applicable method 'Contains' exists in type 'Int32'"

Also tried in another way as below
int[] CandidateIdsArray = new int[]{4, 78, 101}
var dynamicLinqQuery = Candidates.Where("@0.Contains(CandidateId)", CandidateIdsArray);
Runtime Exception - "No property or field 'CandidateId' exists in type 'Int32'"

I have spend almost 2 days to resolve the above problem but not able to succeed. Could any one please help me out in resolving the above issue...Thanks in Advance
Posted
Comments
govardhan4u 26-Mar-13 7:56am    
Try to use Int32 or Integer (Object type)

1 solution

Let me describe what your Problem is:

You have a collection of Candidates.
Your first query is looking if one of the names is containing the names given in CandidateNamesArray - I think this is not what you want, but works because string is an Array of chars and has a Contains method.
Your second query is looking if one of the id's is containing the numbers given in CandidateIdsArray, again this is not what you want, and it does not work because now Int32 doesn't define a Containes() method.

So what you want is something like this

get all candidates with the specified Name(s)
get the candidates with the specified Id(s)

correct?
 
Share this answer
 
Comments
Member 4668039 29-Mar-13 1:16am    
Thanks...What I want is the below
get the candidates with the specified Id(s), I want to check the int array with the Candidates and get all the candidates which are in int array.

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