Chapter 12. Extending LINQ

 

This chapter covers:

  • LINQ’s extension mechanisms
  • Custom query operators
  • The query expression pattern
  • IQueryable and IQueryProvider
  • LINQ to Amazon

When we introduced LINQ, we pointed out that one of its major features is its ability to query several kinds of data and data sources. In the chapters that followed, we focused on LINQ to Objects, LINQ to SQL, and LINQ to XML. In this chapter, we’ll analyze how these flavors of LINQ extend LINQ with support for data sources such as in-memory collections, XML, or relational databases. This will allow you to determine the techniques you can use to extend LINQ and use it with your own data sources. LINQ’s extensibility features will allow you to adapt it to particular needs. They will also enable novel use cases that expand the LINQ spectrum.

LINQ’s extensibility allows you to create your own flavor of LINQ by creating a LINQ provider. Of course, this can be a lot of work. Most of the time you won’t need to create a complete LINQ flavor. You may simply need small adaptations of LINQ’s behavior. Fortunately, LINQ is flexible enough that you can add new query operators or redefine some of the default ones according to your needs. Whether you’re a framework provider who wants to give your users the power of LINQ or simply a developer who wants to adapt LINQ to your own business context, you’ll find that LINQ is flexible enough to adapt to your needs.

12.1. Discovering LINQ’s extension mechanisms

12.2. Creating custom query operators

12.3. Custom implementations of the basic query operators

12.4. Querying a web service: LINQ to Amazon

12.5. IQueryable and IQueryProvider: LINQ to Amazon advanced edition

12.6. Summary