title: How to return nested, one to many relationship in a ASP.NET MVC json response?
body: <p><strong>How would you format a Json response to include nested, one to many related data?</strong></p>
  
  <p>My simple JQuery Autocomplete example.  The Linq2Sql is within.  The first part of this question answered <a href="https://stackoverflow.com/questions/1461664/using-jquery-how-do-you-select-one-element-based-on-anothers-name">here</a>.  This uses a repository with Linq 2 SQL to send the response:</p>
  
  <pre><code>public IQueryable GetProductIDs(string myPrefix, int limit)
  {
      return from z in db.Products
             where z.ItemNo.StartsWith(myPrefix)
             select new { id = z.ItemNo, name = z.DetailText, **** }; 
             //, This is where I need to assemble about 4 related product quantities
             //  like Qty1: 5, PricePer: $3, Qty2: 10, PricePer: $2, Qty3: 25, PricePer: $1
  }
  </code></pre>
  
  <p>It returns a json object:</p>
  
  <pre><code>public ActionResult autocomplete(string q, int limit)
  {
      var jsonData = plantRepository.GetProductIDs(q, limit);
      return Json(jsonData);
  }
  </code></pre>
  
  <p>This currently returns data parse-able with JavaScript:</p>
  
  <pre><code>parse: function(data) {
      var rows = new Array();
      for( var i = 0; i&lt;data.length; i++)
      {   rows[i] = {data:data[i], value:data[i].name, result:data[i].id }; }
      return rows;}
  </code></pre>
  
  <p><strong>So how to you format the Linq 2 SQL to return Json that can be parsed like data[i].price[1].qty, data[i].price[1].pricePer? (or simply add a multi-part object in the initializer?)</strong></p>
  
  <p>I hope this makes sense.  I provided all the information to provide a context because the question in itself didn't make sense to me.</p>