Developing Linq to LLBLGen Pro, part 8
(This is part of an on-going series of articles, started here)
Today I managed to arrive back at the point I stopped with my current code base a couple of weeks ago to re-implement the expression tree reduction code. I'm not totally done with re-connecting the wires of the outer interface code to the inner execution engine, but that's a minor detail. A lot of work is still ahead of me, but I've more confidence in finishing it with a satisfying framework than I have had before during this project so far.
To illustrate what expression tree reduction looks like, I'll show you some screenshots from my expression tree visualizer, which is a reworked and enhanced form based on the expression tree visualizer in the C# examples shipped with VS.NET 2008. I've added to this visualizer a pseudo-SQL engine from our own debugger visualizers shipped with LLBLGen Pro so it's easier to see what the relation objects and predicate objects result in. (I use a custom Windows XP theme, so the screen might look a little unorthodox, so no, it's not linux )
The query which is shown as expression trees is the following one, which is pretty bogus but is solely used to check roughly if the code I had in mind even works out the way I thought it would. As you can see from the screenshots, it ends up in a nice QueryExpression, which is the last Expression based class a tree will end up in in my code so I can hand over this object with all its internal data to the execution engine which will simply grab the data inside it and pass it on to the LLBLGen Pro runtime library.
// C# string city = "Munchen"; var q = from c in metaData.Customer join o in metaData.Order on c.CustomerId equals o.CustomerId join od in metaData.OrderDetail on o.OrderId equals od.OrderId where c.City == city && c.Country == "Germany" && o.EmployeeId == 2 && (od.Quantity * od.UnitPrice) > 500 select (o.EmployeeId > 10);
My current code can recognize predicates, field expressions, joins (not group joins yet), can evaluate local variables into values used into predicates, projections of single fields and entity projections. This is all embedded into the query above. The screenshots are below. I've made thumbnails of the images so the post stays rather small in size. Click a thumbnail to enlarge the image.
There will follow more states and likely this won't be the final order of events. However you can see clearly how the tree gets reduced by recognizing subtrees and replacing these subtrees with a single expression object or other subtree which is easier to handle later on.
Also, for kicks, please pay attention to the expression in text form in the start state's screenshot. 10 to 1 you won't recognize the original query in that.