I am building a restful service to serve requests to a client I do not directly control (Couchbase Lite). The client has a bug that makes a request for 7-11k documents at once. It also requires the response to be multipart which is designed as a nested object response type in WebApi.
Using normal datareaders to get the JSON data from a SQL Server as a big batch and passing them to WebApi creates a large number of objects on the large object heap that the .NET app does not free until the site is restarted. Additionally, I have a need to actually insert some data into each object. Parsing the JSON using JSON.net, inserting a property and re-serializing is very slow and actually doubles the number of large objects on the .NET heap.
Is there an efficient way to stream these results without creating tons of large allocations?