Scenario: I have been given a task that involves creating a web API which will take a date parameter in the url like below:
https://server/controllerrouting/payments?requestdate=08/13/2016
This api will call a stored procedure which uses the date from the url in the select statement. The api will then return the result set as a json response to the calling application which will not be a front end facing application.
Problem: this would normally be no problem to return the result set returned from the stored procedure execution. However, the result set is expected to possibly return up to 350,000 records at around 350 bytes for each record.
Possible Design Solution?
I am looking into utilizing the PushStreamContent
class and pushing the data to a stream for the client to consume.
Question
After executing the stored procedure and reading the result set using DataReader
, can I push each record to the stream at this point in the logic?
Something like :
if (reader.HasRows)
{
while (reader.Read())
{
1.format record
2.serialize to json
3.push record to stream
}
}
else
{
return msg("No rows found");
}
reader.Close();
What is the correct way to do this? Is it possible to just return the large json object the client and not worry about having to stream the data ? Do I need to consider paging with the stored procedure or just retrieve all of the records at once then stream only a chunk at a time to the client ? I'm having a hard time understanding what the best method is to attack this situation.