Introduction of lambda expression and predicate builder

67 %
33 %
Information about Introduction of lambda expression and predicate builder
Technology

Published on March 14, 2014

Author: ltcrd

Source: slideshare.net

Introduction of Lambda Expression and Predicate Builder Bryan lin 2014/03/07

Agenda • Lambda Expression • PredicateBuilder • Implementation of PredicateBuilder

Lambda expression • What is a Lambda Expression? • A lambda expression is an anonymous function and it is mostly used to create delegates in LINQ. Simply put, it's a method without a declaration, i.e., access modifier, return value declaration, and name.

Lambda expression • Why do we need lambda expressions? (Why would we need to write a method without a name?) • Convenience. It's a shorthand that allows you to write a method in the same place you are going to use it. Especially useful in places where a method is being used only once, and the method definition is short. It saves you the effort of declaring and writing a separate method to the containing class.

Lambda expression • Benefits: • Reduced typing. No need to specify the name of the function, its return type, and its access modifier. • When reading the code you don't need to look elsewhere for the method's definition.

Lambda expression • Lambda expressions should be short. A complex definition makes the calling code difficult to read.

Lambda expression • How do we define a lambda expression? • Lambda basic definition: Parameters => Executed code.

PredicateBuilder • Background • Dynamic Predicate Construction • You allow the user to pick, from a check box list, any of the fields that will be included in the query, and to specify the criteria

PredicateBuilder

PredicateBuilder • Background • Dynamic Predicate Construction • You can do a bunch of switch-ing if logic to figure out what kind of query to render by adding a piece of it at a time • Or you can use lambdas and the PredicateBuilder to inject multiple predicates into an expression tree

PredicateBuilder • Using the Code • To combine the two criteria below:

PredicateBuilder • Using the Code • Do with the PredcateBuilder:

PredicateBuilder • Using the Code • And then:

Implementation of PredicateBuilder • Implmentation of and logic:

Implementation of PredicateBuilder • Implementation of or logic:

References • http://www.codeproject.com/Tips/298963/Understand-Lambda- Expressions-in-3-minutes • http://www.codeproject.com/Articles/28580/LINQ-and-Dynamic- Predicate-Construction-at-Runtime • http://www.albahari.com/nutshell/predicatebuilder.aspx

FAQ

Add a comment

Related presentations

Related pages

Lambda Expressions – Part I | vnnotech

Lambda expressions Introduction. ... Lambda expression provides a very clear ... Using Lambda expressions functional interface Predicate life becomes ...
Read more

Dynamic Query in LINQ Using Predicate Builder - C# Corner

This article explains how to create a dynamic query LINQ using Predicate Builder. ... Introduction This tutorial ... expression from the specified lambda ...
Read more

C# 6.0 in a Nutshell - PredicateBuilder

Dynamically Composing Expression Predicates. ... An Invoke expression calls another lambda expression using the given expressions as arguments.
Read more

A universal PredicateBuilder | Monty's Gush

... specified lambda expression. ... predicate builder and intermix Expressions and ... post on A universal PredicateBuilder ...
Read more

lambda - Using PredicateBuilder with VB.NET - Stack Overflow

Using PredicateBuilder with VB.NET. ... expr1.Parameters.Cast(Of Expression)()) Return Expression.Lambda(Of ... predicate = predicate.Or ...
Read more

Java SE 8: Lambda Quick Start - Oracle

... Lambda Quick Start ... Introduction. Lambda expressions are a new and ... The correct syntax for lambda expressions. A Predicate interface to ...
Read more

LINQ and Dynamic Predicate Construction at Runtime ...

LINQ and Dynamic Predicate Construction at Runtime. ... How is that accomplished with predicate builder? ... return Expression.Lambda >
Read more

C# Predicate Type - DotNetPerls

This C# example program uses the Predicate type. A Predicate returns a bool. C#: Lambda ... And it is often used with lambda expression syntax.True, False
Read more

Dynamic Query in LINQ using Predicate Builder - Dot Net ...

Dynamic Query in LINQ using Predicate Builder Introduction. ... expression from the specified lambda expression. /// public ...
Read more