title: select new in linq c#
body: <p>I have one action in my controller of asp.net mvc project.</p>
  
  <pre><code>public JsonResult GetProductBySearch(string Q)
  {
     JsonResult jr = new JsonResult();
     var _product = from a in DataContext.SearchItem(Q)
                    select new { ID = a.ID, ProName = a.Name };
     jr.Data = _product.ToList();
     jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
     return jr;
  }
  </code></pre>
  
  <p>I want to return this json data to the view of my project. It is works well in my view if I used "select new", But as I know, select new is using while we need the sub set of data. But in this query I want to get all the field from my table as below :</p>
  
  <pre><code>public JsonResult GetProductBySearch(string Q)
  {
    JsonResult jr = new JsonResult();
    var _product = from a in DataContext.SearchItem(Q)
                   select a;
    jr.Data = _product.ToList();
    jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
    return jr;
  }
  </code></pre>
  
  <p>This is what I loop in view, It is work very well if  I used with select new.
  But when I change to SELECT, the alert is not work.</p>
  
  <pre><code> $.getJSON(url, data, function (data) {
       alert(1);
     $.each(data, function (index, proValByDep) {
  
     });
   });
  </code></pre>
  
  <p>Any ideas please.</p>