Galin Iliev's blog

Software Architecture & Development

How to build custom LINQ provider?

Many people asked this question since May 2006 LINQ Preview was announced. We know there are several providers implemented by Microsoft:

But if we have custom datastore how we can implement LINQ provider for it? For a long time LINQ to Amazon by Fabrice Marguerie, was the only third-party provider and although he explained it was still many question left opened. (I've just found that there was LINQ to WebQueries by Hartmut Maennel predates LINQ to Amazon by few days.)

Matt Warren started very nice and deep series of blog posts that covers the process of writing custom LINQ provider. Even if you don't plan to write custom provider this post can give you an idea how the things work:

Of course, it is good idea to check if the provider is not written already :) See below list of providers.

OakLeaf Systems blog has a nice post that gives list of third-party LINQ providers (re-posted): 

  • LINQ to WebQueries by Hartmut Maennel handles searches in the SiteSeer and MSDN Web sites. (This provider predates Fabrice's LINQ to Amazon provider by a few days.)
  • LINQ to Amazon by Fabrice Marguerie, a co-author of the forthcoming LINQ in Action book, was the first third-party LINQ provider that I know of. LINQ to Amazon returns lists of books meeting specific criteria.
  • LINQ to RDF Files by Hartmut Maennel handles queries against Resource Description Format files' triples. Part I of the two-part post is here.
  • LINQ to MySQL by George Moudry, based on the LINQ May 2006 CTP, was in the development stage as of January 2007, but George says it's "capable of simplest queries and updates" and "now has support for most primitive joins."
  • LINQ to NHibernate by Ayende Rahien (a.k.a. Oren Eini) translates LINQ queries to NHibernate Criteria Queries and is based on the Orcas March 2007 CTP. The documentation that describes development of the provider presently is at the Part 1 stage.
  • LINQ to LDAP by Bart de Smet is a "query provider for LINQ that's capable of talking to Active Directory (and other LDAP data sources potentially) over LDAP." As of 4/11/2007, Bart's "IQueryable Tales - LINQ to LDAP" consisted of Part 0: Introduction, Part 1: Key Concepts, Part 2: Getting Started with IQueryable, Part 3: Why do we need entities?, Part 4: Parsing and executing queries, and Part 5: Supporting Updates.
  • LINQ to Flickr by Mohammed Hossam El-Din (Bashmohandes) uses the open-source FlickrNet C# library as its infrastructure.
  • LINQ to Google Desktop by Costa Rican programming language enthusiast Luis Diego Fallas supports GDFileResult and GDEmail types. A subsequent Adding support for projections to Linq to Google Desktop implements the LINQ Select expression.
  • LINQ to SharePoint by Bart de Smet supports writing LINQ queries for SharePoint lists in both C# 3.0 and Visual Basic 9.0 and communicates with SharePoint via Web services or though the SharePoint Object Model. The SpMetal command-line utility automates C# or VB class generation.
  • LINQ to Streams (SLinq, Streaming LINQ) by Oren Novotny processes continuous data streams, such as stock tickers or sensor data. The project's home page on CodePlex includes an animated GIF simulation of a stock ticker displayed in a DataGridView. The current version supports Select, Where, Order By, and Descending only.
  • LINQ to Expressions (MetaLinq) by Aaron Erickson (the developer of Indexes for Objects a.k.a i4o*) lets you query over and edit expression trees with LINQ. Like .NET strings, LINQ expression trees are immutable; the only way you can change a LINQ expression tree is to make a copy, modify the copy, and then replace the original. MetaLinq's ExpressionBuilder lets you create an "Editable Shadow of an expression tree, modify it in place, and then by calling ToExpression on the shadow tree, generate a new, normal, immutable tree." ExpressionBuilder is an analog of the .NET StringBuilder.

* i4o isn't a LINQ provider, per se, but a helper class that can increase the speed of LINQ queries against large collections by a factor of 1,000 or more. InfoQ published on June 22, 2007, Aaron Erickson on LINQ and i4o, an interview of Aaron Erickson by Jonathan Allen about i4o's purpose and background.

Hope you'll find this useful