title: Using Devexpress MVC TreeList to list order totals by client
body: <p>I'm trying to implement a DevExpress MVC TreeList that shows a list of clients as the first level of the hierarchy. But when you open one client, the second level must show a list of related orders with their OrderTotal for each order.</p>
  
  <p>I'm trying to base myself on the demo at <a href="http://demos.devexpress.com/MVCxTreeListDemos/DataBinding/DataBinding" rel="nofollow">http://demos.devexpress.com/MVCxTreeListDemos/DataBinding/DataBinding</a> which is similar to what I'm looking for. I'm using the Northwind database as an example.</p>
  
  <p>The model that the TreeList must be based on has to be specific in that it has to have the following structure (maybe I'm wrong on this):</p>
  
  <p>CustomerId, 
  Order.CustomerId,
  CustomerName,
  OrderTotal,
  OrderDate,
  ShipCity</p>
  
  <p>The second one has to be the "ParentId" in order to satisfy the hierarchy structure.</p>
  
  <p>Here is what I have in my controller:</p>
  
  <pre><code>       [ValidateInput(false)]
      public ActionResult OrderTreeListPartial()
      {
          var model = db.Orders.GroupBy(o =&gt; o.Customer)
              .Select(group =&gt; new
              {
                  CustomerId = group.Key.CustomerID,
                  ParentId = group.Select(g=&gt;g.CustomerID),
                  CustomerName = group.Key.CompanyName,
                  OrderTotal = group.Sum(g =&gt; g.OrderTotal),
                  OrderDate = group.Select(g =&gt; g.OrderDate),
                  City = group.Select(g =&gt; g.ShipCity)
              });
  
          return PartialView("_OrderTreeListPartial", model);
      }
  </code></pre>
  
  <p>And I have the following in my _OrderTreeListPartial:</p>
  
  <pre><code>@{
  var treeList = Html.DevExpress().TreeList(settings =&gt;
  {
      settings.Name = "OrderTreeList";
      settings.CallbackRouteValues = new { Controller = "TreeList", Action = "OrderTreeListPartial" };
  
      settings.SettingsEditing.AddNewNodeRouteValues = new { Controller = "TreeList", Action = "OrderTreeListPartialAddNew" };
      settings.SettingsEditing.UpdateNodeRouteValues = new { Controller = "TreeList", Action = "OrderTreeListPartialUpdate" };
      settings.SettingsEditing.DeleteNodeRouteValues = new { Controller = "TreeList", Action = "OrderTreeListPartialDelete" };
      settings.SettingsEditing.NodeDragDropRouteValues = new { Controller = "TreeList", Action = "OrderTreeListPartialMove" };
  
      settings.CommandColumn.Visible = true;
      settings.CommandColumn.NewButton.Visible = true;
      settings.CommandColumn.DeleteButton.Visible = true;
      settings.CommandColumn.EditButton.Visible = true;
  
      settings.AutoGenerateColumns = false;
      settings.KeyFieldName = "CustomerId";
      settings.ParentFieldName = "ParentId";
      settings.RootValue = 0;
  
      settings.Columns.Add(
  column =&gt;
  {
      column.FieldName = "CustomerName";
      }
  );
          settings.Columns.Add(
      column =&gt;
      {
          column.FieldName = "OrderDate";
      }
  );       
          settings.Columns.Add(
  column =&gt;
  {
      column.FieldName = "OrderTotal";
      column.PropertiesEdit.DisplayFormatString = "{0:C}";
  }
  );
          settings.Columns.Add(
      column =&gt;
      {
          column.FieldName = "City";
      }
      );        
  
  
  
     settings.SettingsPager.Visible = true;
          settings.SettingsSelection.Enabled = true;
      });
      if (ViewData["EditError"] != null)
      {
          treeList.SetEditErrorText((string)ViewData["EditError"]);
      }
  }
  @treeList.Bind(Model).GetHtml()
  </code></pre>
  
  <p>I think the problem is in my LINQ expression in my controller. The truth is I'm not an expert in LINQ and I'm evaluating the DevExpress extensions for a future project. Any help would be appreciated, wether in my LINQ or in how I prepared the TreeList.</p>