Indeed, I left that proviso out... In general this seems to be the case for inherited hierarchies, and it's not any worse that random ordering _most_ of the time.
Marc On 5/9/08, Frans Bouma <[EMAIL PROTECTED]> wrote: > > > First, simply fetch the employees in full: > > > var q = from e in ctx.Employees select e; > > > > Excellent description, Frans... one thing I like to point out is that > > if you make your initial (flat) query from the database ordered by the > > parent id and entry id, you get "in-order insertion" behavior when > > building the tree, which makes everything faster: > > > > SELECT ManagerID, EmployeeID, Name > > FROM Employee > > ORDER BY ISNULL(ManagerID, 0), EmployeeID > > No, that's not true. It's only true if employees at level n have all > lower ID's than the employees at level n+1: > > managerID | EmployeeID | Name > ----------------------------------- > 0 | 20 | John D. Rockefeller > 1 | 4 | Rick W. Annabee > 1 | 6 | Al MostThere > > etc. > > :) > So a sorting COULD give a better performance but the sorting should be > taylored towards the ID distribution across the layers in the hierarchy. For > example your sorting could have devastating results for performance in the > situation where all managers have HIGHER ID values than their employees, as > every row except the root will end up in the orphaned list ;) > > FB > > =================================== > This list is hosted by DevelopMentor(R) http://www.develop.com > > View archives and manage your subscription(s) at http://discuss.develop.com > -- "Your lack of planning DOES constitute an emergency on my part... so PLAN BETTER! " Marc C. Brooks http://musingmarc.blogspot.com =================================== This list is hosted by DevelopMentor� http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com