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.
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.
I am trying to build a JSON structure with the following hierarchy:
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
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:
{
"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
// ...
]
}
}
Currently the only linq expressions I have are:
public IQueryable<vwBatchList> AggregateBatchList(int coid)
{
var contex = new LBPEntities();
var batchList =
(from x in contex.vwBatchLists
where x.CoId == coid
select x);
return batchList;
}
Which I can then encode the results and pass to a grid.
But i want to relate it to this expression which references the batch number:
public IQueryable<vwBatchDetail> AggregateBatchDetails(string batchNumber)
{
var contex = new LBPEntities();
var batchDetails =
(from x in contex.vwBatchDetails
where x.BatchNumber == batchNumber
select x);
return batchDetails;
}
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.