More and more I’ve been using projections to handle the query side of my applications, which of course includes a lot of
The problem with
Expression objects is they’re non-trivial to chain together and combine, because they’re data structures, not code.
I recently had to implement a simple report filter that had optional date ranges on 4 different date fields - each with an optional From and To date. Of course, there were other requirements of this feature, too, which makes it a bit more interesting:
- Run the whole query in SQL - I don’t want to materialize my enumerable to perform the filtering
- Somewhat simple SQL query - of course I can be clever with
SelectMany, but I’d prefer my SQL to just say
WHERE date <= @p0 if possible.
- Clean code - DRY, reusable, terse et. al.