title: Lambda Expression for OrderBy
body: <pre><code>///  Model
  public class MenuModels
  {
      public Int32 MenuId { get; set; }
      public string MenuName { get; set; }
      public Int32 MenuLevel { get; set; }
      public Int32 MenuParent { get; set; }
      public string MenuUrl { get; set; }
  }
  
  ///    In my Controller I have this code
  Menus = menuRepository.GetAll().OrderBy(y=&gt;y.menu_id+y.menu_parent+y.menu_level).ToList()
  </code></pre>
  
  <p>I want to get all the menus in ascending order by sum of 3 fields(id,parentId,level).</p>
  
  <p>or else concatenation of 2 fields(id,parentId)</p>
  
  <pre><code>menuRepository.GetAll().OrderBy(y=&gt;int.parse(y.menu_id.ToString+y.menu_parent.ToString)).ToList()
  </code></pre>
  
  <p>Basically im creating a MENU Create Controller in that i have a dropdownlist that fills the all the menus, but i want to fill menus in dropdown like</p>
  
  <pre><code>Home
  --submenu1
  --submenu2
  Contact
  --submenu1
  --submenu2
  </code></pre>
  
  <p>for this i have written code below</p>
  
  <pre><code>        var menuModel = new MenuModels()
          {
              Menus = menuRepository.GetAll().ToList().Select(x =&gt;
                             {
                                 var level = x.menu_level;
                                 return (level == 0)
                                            ? new SelectListItem {Text = x.menu_name, Value = x.menu_id.ToString()}
                                            : new SelectListItem {Text = "-- "+x.menu_name, Value = x.menu_id.ToString()};
                             })
           };
          return View(menuModel);
  </code></pre>
  
  <p>But this doesn't give me what im expecting and i know why, 
  in database i have table like</p>
  
  <pre><code>id   level   parent   name
  ---------------------------
  1    0       0        Home
  2    0       0        About
  3    1       1        submenu1
  4    1       1        submenu2
  5    1       2        submenu1
  </code></pre>
  
  <p>i made sql query for this to get better understanding my problem</p>
  
  <pre><code>select *,( Convert(nvarchar(50),(case when menu_parent=0 then menu_id else menu_parent end))  + '' +  Convert(nvarchar (50),(menu_parent)))
   as Sort from menu order by Sort,menu_id
  </code></pre>
  
  <p>this query results like</p>
  
  <pre><code>id   level   parent   name      Sort
  ------------------------------------
  1    0       0        Home       10
  3    1       1        submenu1   11
  4    1       1        submenu2   11
  2    0       0        Abount     20
  5    1       2        submenu1   22
  </code></pre>