Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I need a lemda expression with dynamic column like below example

C#
var item=listItem.Where(DynamicColumn.Contains(textValue));

or
C#
var item=listItem.Where(a=>a.DynamicColumn.Contains(textValue));


What I have tried:

I have tried to do it by the same way i have discussed in the question description but it's not working.
Posted
Updated 18-Mar-16 4:01am
v2

1 solution

The solution is to dynamically build the required expression tree which normally gets done for you "under the hood" by using those LINQ methods.

That's a moderately advanced topic but you don't have to do it yourself: There already are several solutions for this which you could use:

Build Lambda Expressions Dynamically[^]
Dynamic Expresso[^]
LINQ and Dynamic Predicate Construction at Runtime[^]
Build Where Clause Dynamically in Linq[^]
GitHub - kahanu/System.Linq.Dynamic: This is the Microsoft assembly for the .Net 4.0 Dynamic language functionality.[^]
 
Share this answer
 
v2

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