Click here to Skip to main content
15,881,712 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Public void List()
{
   string x="";

foreach( var item in t)
{
    x=  ....
}

}



I want to write the string values ​​in my hand in lambda. But when I write as where I get an error.

What I have tried:

var c=MyStudent.tblStudent.Select(x=>x.tblPerson).Distinct().ToList();



I want to where condition string x variable including.
How to write string x variable.

Try To:

var c=MyStudent.tblStudent.Where(x).Select(x=>x.tblPerson).Distinct().ToList(); ////but where(x) is error.

How to lambda expression where condition in string variables.
Posted
Updated 8-Jan-20 20:36pm

Seems you want to create a where statement dynamically. So, please read this: How to use expression trees to build dynamic queries (C#) | Microsoft Docs[^]

Here[^], you you'll find quite simple example.
 
Share this answer
 
Where requires a condition, perhaps something like this:
var c=MyStudent.tblStudent.Where(x => x.Contains("John")).Select(x=>x.tblPerson).Distinct().ToList();
 
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