I didn't intend to post so quickly after my last post, but some comments from Nick motivated me to try something different.
So what's changed?
Not much. Defining your query properties has changed (and obviously some implementation details). All the linq syntax stuff stays the same.
Here's the same Loan class, rewritten:
And here's our query property definition:
What's the difference?
Well, depending on your programming tastes, it's cleaner. We've reduced some of the tight coupling, and we now have the ability to spread the logic (which is more suitable in certain situations).
And if you're wondering why I seem to have an obsession with static members, it's mainly due to performance - and truth be told, I'm pre-optimizing here. Generally I'm not such a fan... honest!
Speaking of performance, using Attributes has a penalty. According to my tests, it's roughly 30% slower to parse the expression.
This might sound like a lot, but we're talking about 0.37 vs 0.28 milliseconds per query here - and once you consider the database retrieval time... it's really nothing.
I don't even parse the expression tree with linq to objects - so no impact at all!
Bonus code (Expression Parser)
Here's my expression parsing code, I know you want to see it:
Beautiful isn't it!
If you've been following this little series, I'd love to hear what you think of the new syntax.
I'm still hesitant, since this new syntax results in more code - but I think it's a cleaner approach.
As usual, you can find the sample app here - enjoy!