title: Return Array from Linq Query
body: <p>I'm trying to convert the following code to return an array result. But am unable to get it to work. I'm fairly new to the Linq framework.</p>
  
  <p>Here is the Code I have:</p>
  
  <pre><code>// GETAll api/category
  public IEnumerable&lt;Category&gt; GetAll()
  {
      nopMass db = new nopMass();
  
      var model = db.Categories.Where(x =&gt; x.ParentCategoryId == 0);
  
      return model.ToArray();
  }
  </code></pre>
  
  <p>This is what I want it to return</p>
  
  <pre><code>// GETAll api/category
  public IEnumerable&lt;Category&gt; GetAll()
  {
      return new Category[]
      {
          new Category
          {
              ParentCategoryId = 1,
              Name = "New Vehicles"
          },
          new Category
          {
              ParentCategoryId = 2,
              Name = "Used Vehicles"
          }
      };
  }
  </code></pre>
  
  <p>When I access the first code in HTML I don't get a result displaying. The second code gives an output.</p>
  
  <p>Here is Html and Jquery Code</p>
  
  <pre><code>&lt;ul id="products" /&gt;
  
  &lt;script&gt;
       var uri = 'api/category';
  
       $(document).ready(function () {
           // Send an AJAX request
           try
           {
               $.getJSON(uri)
                   .done(function (data) {
                       // On success, 'data' contains a list of products.
                       $.each(data, function (key, item) {
                           // Add a list item for the product.
                           $('&lt;li&gt;', { text: formatItem(item) }).appendTo($('#products'));
                       });
                   });
           }
           catch (e) {
               alert(e.message);
           }
  });
  
  function formatItem(item) {
      return item.Name;
  }
  
  &lt;/script&gt;
  </code></pre>