You are previewing LINQ Pocket Reference, one of over 30,000 titles on Safari
LINQ Pocket Reference

Book Description

Ready to take advantage of LINQ with C# 3.0? This guide has the detail you need to grasp Microsoft's new querying technology, and concise explanations to help you learn it quickly. And once you begin to apply LINQ, the book serves as an on-the-job reference when you need immediate reminders. All the examples in the LINQ Pocket Reference are preloaded into LINQPad, the highly praised utility that lets you work with LINQ interactively. Created by the authors and free to download, LINQPad will not only help you learn LINQ, it will have you thinking in LINQ. This reference explains:

  • LINQ's key concepts, such as deferred execution, iterator chaining, and type inference in lambda expressions

  • The differences between local and interpreted queries

  • C# 3.0's query syntax in detail-including multiple generators, joining, grouping, query continuations, and more

  • Query syntax versus lambda syntax, and mixed syntax queries

  • Composition and projection strategies for complex queries

  • All of LINQ's 40-plus query operators

  • How to write efficient LINQ to SQL queries

  • How to build expression trees from scratch

  • All of LINQ to XML's types and their advanced use

  • LINQ promises to be the locus of a thriving ecosystem for many years to come. This small book gives you a huge head start.

    "The authors built a tool (LINQPad) that lets you experiment with LINQ interactively in a way that the designers of LINQ themselves don't support, and the tool has all kinds of wonderful features that LINQ, SQL and Regular Expression programmers alike will want to use regularly long after they've read the book." -Chris Sells, Connected Systems Program Manager, Microsoft

    Table of Contents

    1. LINQ Pocket Reference
    2. 1. LINQ Pocket Reference
      1. Getting Started
      2. Lambda Queries
        1. Chaining Query Operators
        2. Composing Lambda Expressions
          1. Lambda expressions and Func signatures
          2. Lambda expressions and element typing
        3. Natural Ordering
        4. Other Operators
      3. Comprehension Queries
        1. Iteration Variables
        2. Query Syntax Versus SQL Syntax
        3. Query Syntax Versus Lambda Syntax
        4. Mixed Syntax Queries
      4. Deferred Execution
        1. Reevaluation
        2. Outer Variables
        3. How Deferred Execution Works
        4. Chaining Decorators
        5. How Queries Are Executed
      5. Subqueries
        1. Subqueries and Deferred Execution
      6. Composition Strategies
        1. Progressive Query Building
        2. The into Keyword
          1. Scoping rules
        3. Wrapping Queries
      7. Projection Strategies
        1. Object Initializers
        2. Anonymous Types
        3. The let Keyword
      8. Interpreted Queries
        1. How Interpreted Queries Work
          1. Execution
        2. AsEnumerable
      9. LINQ to SQL
        1. LINQ to SQL Entity Classes
        2. DataContext
        3. Automatic Entity Generation
        4. Associations
        5. Deferred Execution with LINQ to SQL
        6. DataLoadOptions
          1. Specifying a filter in advance
          2. Eager loading
        7. Updates
      10. Building Query Expressions
        1. Delegates Versus Expression Trees
          1. Compiling expression trees
          2. AsQueryable
        2. Expression Trees
          1. The Expression DOM
      11. Query Operator Overview
      12. Filtering
        1. Where
          1. Comprehension syntax
          2. Overview
          3. Indexed filtering
          4. Where in LINQ to SQL
        2. Take and Skip
        3. TakeWhile and SkipWhile
        4. Distinct
      13. Projecting
        1. Select
          1. *Comprehension syntax
          2. Overview
          3. Indexed projection
          4. Select subqueries and object hierarchies
          5. Subqueries and joins in LINQ to SQL
          6. Projecting into concrete types
        2. SelectMany
          1. Comprehension syntax
          2. Overview
          3. Outer iteration variables
          4. Thinking in comprehension syntax
          5. Joining with SelectMany
          6. SelectMany in LINQ to SQL
          7. Outer joins with SelectMany
      14. Joining
        1. Join and GroupJoin
          1. Join arguments
          2. GroupJoin arguments
          3. Comprehension syntax
          4. Overview
          5. Join
          6. Joining on multiple keys
          7. Joining in lambda syntax
          8. GroupJoin
          9. Flat outer joins
          10. Joining with lookups
      15. Ordering
        1. OrderBy, OrderByDescending, ThenBy, ThenByDescending
          1. OrderBy, OrderByDescending arguments
          2. ThenBy, ThenByDescending arguments
          3. Comprehension syntax
          4. Overview
          5. Comparers and collations
          6. IOrderedEnumerable and IOrderedQueryable
      16. Grouping
        1. GroupBy
          1. Comprehension syntax
          2. Overview
          3. GroupBy in LINQ to SQL
          4. Grouping by multiple keys
          5. Custom equality comparers
      17. Set Operators
        1. Concat and Union
        2. Intersect and Except
      18. Conversion Methods
        1. OfType and Cast
        2. ToArray, ToList, ToDictionary, ToLookup
        3. AsEnumerable and AsQueryable
      19. Element Operators
        1. First, Last, Single
        2. ElementAt
        3. DefaultIfEmpty
      20. Aggregation Methods
        1. Count and LongCount
        2. Min and Max
        3. Sum and Average
        4. Aggregate
      21. Quantifiers
        1. Contains and Any
        2. All and SequenceEqual
      22. Generation Methods
        1. Empty
        2. Range and Repeat
      23. LINQ to XML
        1. Architectural Overview
      24. X-DOM Overview
        1. Loading and Parsing
        2. Saving and Serializing
      25. Instantiating an X-DOM
        1. Functional Construction
        2. Specifying Content
        3. Automatic Deep Cloning
      26. Navigating/Querying an X-DOM
        1. Child Node Navigation
          1. FirstNode, LastNode, and Nodes
          2. Retrieving elements
          3. Retrieving a single element
          4. Recursive functions
        2. Parent Navigation
        3. Peer Node Navigation
        4. Attribute Navigation
      27. Updating an X-DOM
        1. Simple Value Updates
        2. Updating Child Nodes and Attributes
        3. Updating Through the Parent
          1. Removing a sequence of nodes or attributes
      28. Working with Values
        1. Setting Values
        2. Getting Values
        3. Values and Mixed Content Nodes
        4. Automatic XText Concatenation
      29. Documents and Declarations
        1. XDocument
        2. XML Declarations
      30. Names and Namespaces
        1. Specifying Namespaces in the X-DOM
        2. The X-DOM and Default Namespaces
        3. Prefixes
      31. Projecting into an X-DOM
        1. Eliminating Empty Elements
        2. Streaming a Projection
        3. Transforming an X-DOM
    3. Index
    4. About the Authors
    5. Copyright