3. 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.
4. 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.
5. 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.
6. Lambda expression
• Lambda expressions should be short. A complex definition makes the
calling code difficult to read.
7. Lambda expression
• How do we define a lambda expression?
• Lambda basic definition: Parameters => Executed code.
8. 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
10. 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