bcallister (4) [Avatar] Offline
i am a developer in need of some guidance in building a custom LINQ Provider.

the backend data source for my provider is Azure Table storage. a common client-side query might look like this:

var query = (
from m in Medication.Samples
join d in Demographics.Samples on m.UID equals d.UID
where (m.Dosage == "250"smilie && (d.Age > 50)
select new { ... });

my source types above implement IQueryable. when Execute() gets called on my IQueryProvider, i am using MetaLinq to serialize my Expression Tree to the server-side (an Azure Worker Role) where the query execution actually occurs.

on the server-side, i want to essentially partition the above where clause into its source-specific components (e.g. Dosage with Medication AND Age with Demographics), each which translates to a seperate Azure Table (since Azure Tables dont support Joins).

i will then need to query each table individually using its specific components, bring these independent results back into memory on the server-side, and finally perform a join using LINQ to Objects, LINQ to XML, or LINQ to DataSets on the in-memory result collections. i then have a helper class which would translate the client query's projected anonymous type into XML for transmission back to the client-side.

my first question is do you know of a clever/elegant way to accomplish this task of breaking up the where clause into separate queries that will work against Azure Tables using System.Data.Services?

basically, i need to accomplish the following:

1) get original query Expression Tree on server-side (via MetaLinq).

2) breakup where clause into N queries, one for each Azure Table involved. the correct sub-expressions from the where clause need to be applied to each sub-query.

3) execute N sub-queries and then inject the results into memory on the server-side, where they can finally be queried together using the specified Join (via LINQ to Objects, LINQ to XML, OR LINQ to DataSets).

4) serialize the results as XML and return to the client-side.

i am fine with the current operator limitations within the where clause for Azure Tables, but Join support is a must, so i need to be able to elegantly support this capability. and i have been going a bit nuts trying to figure out a good way to achieve steps #2 and #3.

also, there is something else that i ran into. given this query:

string sPrefix = "x-";
var query = (
from m in Medication.Samples
join d in Demographics.Samples on m.UID equals d.UID
where (m.Dosage == sPrefix + "250"smilie && (d.Age > 50)
select new { ... });

when i inspect the expression tree, i see a reference to the 'sPrefix' variable, but NOT the actual value! how am i supposed to deal with this in LINQ? i need the actual value on the server-side in order to be able to run the query as the user expects?

i appreciate any feedback you can offer me.