I have an MVC3 program in which I want to query a database and then based on IQueryable returned but the query build a new IQueryable object that will contain item from the original IQueryable but slightly post-processed.
I could of course build a better query in the first place but the problem is the post-processing I need isn’t that easy to do in SQL, but I would do it in C# trivially.
So in effect I need a container-like class that implements IQueryable and I’m not fond of idea of implementing it myself.
Is there a ready class that implements IQueryable?
Your question is strange.
If you want to preprocess all results, then you either have to load them all first and preprocess. Then, they will be stored in IEnumerable. Which seems like a good idea, if there are reasonable amount of results, and you don’t need server sorting, etc.
The other way, is to append
Selectto your IQueryable and do some processing in it without loading actual data (processing will take place on the server side). But in this case you are very limited by the ORM implementation that you use.The next other way, I would do some extended processing logic and still getting result via IQueryable is by putting all processing logic into Table-valued function (or view) in SQL server, and then mapping it to your ORM, and querying it.
The whole idea of IQueryable is that it does not have the data, it is only a defintion of DB query that will be performed upon enumeration.