This was my first attempt to get into roots of LINQ framework, and as a result did good amount of research on this topic. The problem context i am trying to solve is creating an abstract datastore that is then referenced throughout the application. for example i have 2 data stores for storing stock and historical prices.
IDataStore stkStore = CreateDiskStore() //this call returns SQLDataStore
IDataStore priceStore = CreateMemoryStore() //this call return In-memory or Memcache based cache store
var results = (from stk in stkStore where Name == “MSFT” ) ;
Instead of using LINQ to SQL Provider, took the route of creating a simple LINQ to SQL Provider that provides basic feature of SQL that includes Projection, Conditional, Order By clause. Also there are no database joins supported in my LINQ to SQL provider, this is one of the basic principle of building a high scalable “clould” enabled application, this would warrant a separate post.
The motivation behind this route is most of my existing database code is using IBATIS Data Mapper Framework, and by layering LINQ over IBATIS, was able to get best of both worlds. So LINQ Query are translated into expression tree, and then they are translated into SQL query, and married with IBATIS framework to pull up the required dataset and do the appropriate mapping.
So anyone who have worked with IBATIS will know that database mapping with domain object is configured in IBATIS data mapper file, so the only part that are missing are select statements that are determined on the fly based on LINQ query.
The following two article is a must read if any one is venturing in writing their own custom LINQ provider
1. Intro to Expression Tree
2. Building a LINQ Provider