title: Solution for category tree with less query?
body: <p>Basically, the Model is like this:</p>
  
  <pre><code>----------------------------------
  | CAT_ID | CAT_NAME | CAT_PARENT |
  ----------------------------------
  </code></pre>
  
  <p>which  make this a recursive relationship. But how should we use this model in our Asp.net mvc web application with least amount of query. My temporary solution is pass the object in to the function and let the function pass the object, instead of requerry, but this is the code i tried:</p>
  
  <pre><code>public string CategoryTree(this HtmlHelper html, IEnumerable&lt;Category&gt; categories, int? parent)
  {
      parent = parent ?? 0;
      string htmlOutput = string.Empty;
      var cat = categories.Where(d =&gt; d.CAT_PARRENT == parent.Value);
      if (cat.Count() &gt; 0)
      {
          htmlOutput += "&lt;ul&gt;";
          foreach (Category category in cat)
          {
              htmlOutput += "&lt;li&gt;";
              htmlOutput += category.CAT_NAME;
              htmlOutput += html.CategoryTree(categories, category.CAT_ID);
              htmlOutput += "&lt;/li&gt;";
          }
          htmlOutput += "&lt;/ul&gt;";
      }
  
      return htmlOutput;
  }
  </code></pre>
  
  <p>but this generate like 4 query for 4 row of category. So this is not a good solution for this problem. Im using linq to sql.</p>