Your SlideShare is downloading. ×
0
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 c...
Lambda expression
• Why do we need lambda expressions? (Why would we need to write a
method without a name?)
• Convenience...
Lambda expression
• Benefits:
• Reduced typing. No need to specify the name of the function, its return type, and
its acce...
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...
PredicateBuilder
PredicateBuilder
• Background
• Dynamic Predicate Construction
• You can do a bunch of switch-ing if logic to figure out w...
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.c...
FAQ
Upcoming SlideShare
Loading in...5
×

Introduction of lambda expression and predicate builder

703

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
703
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Introduction of lambda expression and predicate builder"

  1. 1. Introduction of Lambda Expression and Predicate Builder Bryan lin 2014/03/07
  2. 2. Agenda • Lambda Expression • PredicateBuilder • Implementation of PredicateBuilder
  3. 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. 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. 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. 6. Lambda expression • Lambda expressions should be short. A complex definition makes the calling code difficult to read.
  7. 7. Lambda expression • How do we define a lambda expression? • Lambda basic definition: Parameters => Executed code.
  8. 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
  9. 9. PredicateBuilder
  10. 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
  11. 11. PredicateBuilder • Using the Code • To combine the two criteria below:
  12. 12. PredicateBuilder • Using the Code • Do with the PredcateBuilder:
  13. 13. PredicateBuilder • Using the Code • And then:
  14. 14. Implementation of PredicateBuilder • Implmentation of and logic:
  15. 15. Implementation of PredicateBuilder • Implementation of or logic:
  16. 16. 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
  17. 17. FAQ
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×