Creating Lambda Expressions dynamically

Lets start by understanding what are Lambda Expressions . These are Expressions which are LINQ to check a condition .

For example : LINQ Where Clause gets a Lambda expression and based on tyhe condition outputs the record .

Lambda Expressions look like following  :  p =>  p.Name = "M"

The code to construct a Lambda Expression is as shown below :

           var param = Expression.Parameter(typEntity, "p");
            var len = Expression.PropertyOrField(param, "Name");
            var body = Expression.Equal(len, Expression.Constant("M"));
            var lambda = Expression.Lambda(body, param);

The above code would construct a Lambda Expression p =>  p.Name = "M"

Thanks ,
Mahadesh

        
Ebook Download
View all

test-2

Read by 0 people
Download Now!
Learn
View all