Click here to Skip to main content
15,890,378 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
string variables=“ “;

foreach(var item in IDList)
{
variables += item.IdCode+”,”;
}

I want to variables use lambda expression but variables get 1,2,3,4 list.

var t=mystudent.tablea.where(x=>x.Id.Contains(variables).ToList();

But this code not run id value is 0.I want to 4 value.

What I have tried:

var t=mystudent.tablea.where(x=>x.Id.Contains(variables).ToList();
Posted
Updated 12-Jan-20 22:58pm

Try this:
C#
int[] ids= new int[]{1, 2, 4};
var t=mystudent.tablea.Where(x=> ids.Any(y=>y == x.Id)).ToList();
 
Share this answer
 
Comments
Wendelius 17-Jan-20 14:48pm    
A 5
Maciej Los 18-Jan-20 0:11am    
Thank you very much, Mika.
Try Googling
linq equivalent of sql 'in'
and see the Stack Overflow result.
Basically, I think you've got the test back-to-front. You're looking to see if ID contains a single value which is a string of concatenated values - it doesn't, it only contains a single value. You want to see if the list (big hint here) of values contains the single value that you are looking for.
 
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