Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating hierarchical JSON result from multiple tables using linq expression
    primarykey
    data
    text
    <p>I have seen a few responses on SO dealing with PHP and JSON but using linq is throwing a wrench into what I am trying to do.</p> <p>High Level: I have two views, BatchList and BatchDetails. BatchList is a view of all batches in my database while BatchDetails has a list of all the orders in a given batch.</p> <p>I am trying to build a JSON structure with the following hierarchy:</p> <pre><code>BatchList.BatchNumber 1 Parent BatchDetails.OrderNumber 1 Children bound by related BatchNumber 1 BatchDetails.OrderNumber 2 BatchDetails.OrderNumber 3 BatchList.BatchNumber 2 Parent BatchDetails.OrderNumber 1 Children bound by related BatchNumber 2 BatchDetails.OrderNumber 2 BatchDetails.OrderNumber 3 </code></pre> <p>I know once I build this that I can just JSON encode it and pass it to my view to display. I have seen examples like:</p> <pre><code>{ "d" : { "results": [ { "CategoryID": 1, "CategoryName": "Beverages", "Description": "Soft drinks, coffees, teas, beers, and ales", "Products": { "results": [ { "ProductID": 1, "ProductName": "Chai", "QuantityPerUnit": "10 boxes x 20 bags" }, // ... // Product 2 // ... ] } }, // ... // Category 2 // ... ] } } </code></pre> <p>Currently the only linq expressions I have are:</p> <pre><code>public IQueryable&lt;vwBatchList&gt; AggregateBatchList(int coid) { var contex = new LBPEntities(); var batchList = (from x in contex.vwBatchLists where x.CoId == coid select x); return batchList; } </code></pre> <p>Which I can then encode the results and pass to a grid.</p> <p>But i want to relate it to this expression which references the batch number:</p> <pre><code>public IQueryable&lt;vwBatchDetail&gt; AggregateBatchDetails(string batchNumber) { var contex = new LBPEntities(); var batchDetails = (from x in contex.vwBatchDetails where x.BatchNumber == batchNumber select x); return batchDetails; } </code></pre> <p>But creating that from two related tables in a database is escaping me. I have not been able to find any good solid JSON tutorials dealing with this problem, all examples generally have hard coded hierarchies.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload