Do you have a real world example we could discuss? That might be easier to talk meaningfully about instead of hypotheticals. I sums because it has examples directly in OP.
What sort of problems are you solving where you need to query unknown shit in unknown ways? Do you think you might have overgeneralized and overcomplicated the problem in some way?
But does it make sense to combine enumerables and queryables? Is accessing a list the same thing as accessing sets in a database? I'd say no.
One advantage is that you abstract the manner in how the data is filtered and transformed. This is useful when dealing with multiple sources of the same type of data. For example, in blended levels of cached data (local RAM, memcached/redis, and a backing database), the extension methods of LINQ can be materialized as execution plans for the remote data sources which optimizes access. For example, the database query can be created from the expression tree so you don’t have to write custom queries for every database call, nor do you need to read in useless data. You can go from three different iteration algorithms for each level of the cache to one expression that can be used optimally for each source.
But those things are not the same. Filtering a list in memory doesn't have the same failure mode as a remote db call, they don't have the same performance. They just are not equivalent. There's plenty of cases where a Linq query won't "materialize" into anything you actually want.
Don't get me wrong, high level tools like JOOQ can make sense, but unifying them across database and memory levels is just not a good idea.
Writing the SQL queries is way easier than trying to reason about what comes out of Linq, especially if you use the same expression for in memory and database access. Writing a few SQL queries just isn't that hard.
Clearly yes, the different sources have different performance characteristics, execution plans, etc. That’s the point of having caching in the first place. What LINQ provides is a high-level abstraction so that your code is clearer to interpret. C# does not really support higher kinded types generally, but LINQ does provide some aspect of that with respect to certain collection generics. Writing SQL by hand can be faster. Writing the query directly for the caching service can be faster. But the compiler support for LINQ, as well as a well-tuned evaluator for the expression trees (likely with its own memoization) lends to nearly if not perfectly comparable performance to these hand-tuned solutions, with the additional benefit of highly readable code.
2
u/Beaverman May 25 '19
Do you have a real world example we could discuss? That might be easier to talk meaningfully about instead of hypotheticals. I sums because it has examples directly in OP.
What sort of problems are you solving where you need to query unknown shit in unknown ways? Do you think you might have overgeneralized and overcomplicated the problem in some way?
But does it make sense to combine enumerables and queryables? Is accessing a list the same thing as accessing sets in a database? I'd say no.