When using For Auto SQL to select large amounts of data in C#, the JSON data is split into multiple strings and won't parse

Viewed 284

I am trying to retrieve some SQL data from anonymous type. Different queries may be passed into the SqlQuery option so I am trying to retrieve the data as JSON and then parse that JSON later on. The problem I run into is the data is automatically split into a string array once it reaches I think 2kb, this means that the parse fails because the split creates invalid JSON. I am looking for a way to change this query either so it splits the data on each new row instead of randomly, or some way to keep it in one string so I can parse it to JSON, or some other way to parse the result to JSON data. Example Query

var data =_invoices.GetContext().Database().SqlQuery("Select * from " + tableName + " For JSON AUTO");
//throws error here because the data is split causing json to be invalid
var json = JArray.parse(data);

The result of this data is splits at a certain size rather than at end of row, which causes my JSON object to be invalid, how can I fix this and get my rows as a valid JSON object

0 Answers
Related