This should be the last part in my series of posts. In this part I'll cover support for parameters via method calls.
Parameter Support (Contrived Example)
Continuing the Library example, how would you query the books that will be overdue next week?
Well you could write the following:
How it works
The CheckOverdue Property simply returns a Lambda Expression as it's result.
I've modified the expression parsing routines to support parameters (including multiple) and even nested lambdas!
I can't really see the need for it, but hey... why not! Curry anyone? :)
So how would you call such a monstrosity?
But check out the SQL! Great work Linq to Sql guys!
If you're particularly astute, you'll have noticed that my syntax for declaring a QueryProperty has changed slightly since the last post.
Here's the class declaration of the CheckOverdue Property:
Although this is a method, you can still define it as a property (notice that I return a lambda expression).
So What's Changed?
Well, QueryProperties no longer derive from an Attribute class. Although it worked, I felt dirty about it.
I borrowed from Fredrik's syntax and pass the property type to the Attribute - much cleaner.
Since I'm no longer defining the QueryProperty as static, I had to change the way it is referenced by the class property.
The code above shows my attempt at making this easy, yet efficient - but it's up to you how to implement it. E.g. this would work well too:
If you can think of better ways I'd love to hear it!
Since I posted the parser code in my last post, here it is again - and my has it grown!
As usual, here is the sample code for you to experiment with yourself.
I hope you've enjoyed this series, I certainly have.
If I get the chance I might write a post explaining the expression parsing in detail, or the compiled queries - but till then...