none
Ordering Child Results RRS feed

  • Question

  • I have a recursive relationship defined on a table.  I.E.  EmployeeID, EmployeeParentID defines an employee and the parent ID defines the manager.

    When I get the top level manager, it automatically gets all the children recursively - which is great - but I am showing these results in a bound WPF treeview and I need to order by last name. 

    How can I order the child results in the parent object?
    Tuesday, June 2, 2009 10:18 PM

Answers

  • Use DataLoadOptions:

       var options = new DataLoadOptions();
       options.AssociateWith <Employee> (e => e.Children.OrderBy (child => child.LastName));
       db.LoadOptions = options;

    Joe

    Write LINQ queries interactively - www.linqpad.net
    • Marked as answer by Burke Holland Wednesday, June 3, 2009 1:12 PM
    Wednesday, June 3, 2009 5:54 AM
    Answerer

All replies

  • Use DataLoadOptions:

       var options = new DataLoadOptions();
       options.AssociateWith <Employee> (e => e.Children.OrderBy (child => child.LastName));
       db.LoadOptions = options;

    Joe

    Write LINQ queries interactively - www.linqpad.net
    • Marked as answer by Burke Holland Wednesday, June 3, 2009 1:12 PM
    Wednesday, June 3, 2009 5:54 AM
    Answerer
  • Joe

    Thanks a million.  I thought I read somewhere that DataLoadOptions were not supported on recursive associations, but it appears to work great.
    Wednesday, June 3, 2009 1:13 PM