Assuming that you have a self-referential relationship for the table, you could do something like:
var q = db.People .OrderBy( p => p.ParentID == null ? p.Name : p.Parent.Name + ":" + p.ID + ":" + p.Name );
This is what the SQL might look like although it does not group the children with their parents. I don't think you can do the grouping using CTEs:
WITH DirectReports (ID, Name, ParentID, Level) AS ( SELECT e.ID, e.Name, e.ParentID, 0 AS Level FROM Employee e WHERE e.ParentID IS NULL UNION ALL SELECT e.ID, e.Name, e.ParentID, Level + 1 FROM Employee E JOIN DirectReports AS d ON e.ParentID = d.ID ) SELECT * FROM DirectReports
- getting nested results from linq to sql
- creating Linq to sqlite dbml from DbLinq source code
- Using Linq when getting value from nested list
- Getting the right results from a LINQ statement
- c# Linq or code to extract groups from a single list of source data
- C# LINQ SPROC Getting Results FROM page number
- Limit Number of Results being returned in a List from Linq
- EF Core nested Linq select results in N + 1 SQL queries
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Accessing Results View from variable in code
- Select object from nested collection using Linq
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Linq to SQL - How to sort results from query
- Linq getting a list from another list
- LINQ Getting Unique items from a List within a List
- LINQ - get total count of values from nested list
- How do I ignore/remove non-number values from linq query results C#
- How to pass LinQ Expressions from F# to C# code
- How to consolidate results from multiple IEnumerable<T> using LINQ
- Check if results from LINQ query contains a value
- Using LINQ to delete an element from a ObservableCollection Source
- Using LINQ to get the results from another LINQ collection
- How does linq actually execute the code to retrieve data from the data source?
- Plinq gives different results from Linq - what am I doing wrong?
- LINQ Source Code Available
- Getting distinct and ordered members from a list of strings - linq or hashset for unique which one is faster / better suited
- EBay OData Type Provider in F# and getting no results with LINQ
- Selecting first element of a group from LINQ search results
- Why am I getting different results filtering with foreach vs LINQ .Where()?
- LINQ - Getting all child records from all parents
- How to convert this LINQ to Entities query into 'Method Syntax' instead of 'Query Syntax'
- How to write Linq query for a Json file?
- Unable to cast object of type 'ImagesFlag' to type 'System.Collections.Generic.IEnumerable`1[ImagesFlag]'
- Ordering Distinct values with LINQ
- Error while calling function from linq query
- Querying external data source with LINQ
- Where clause in Linq and compare strings
- How to aggregate and SUM EntityFramework fields with multiple joins
- INNER JOIN (SELECT * FROM WHERE ...) to Linq
- How to compare array of elements with the linq query result in c#
- How to select several specific elements in LINQ?
- How to find the next element in a generic List?
- LINQ CROSS JOIN Error
- Updating XML file in C#
- One-To-Many relationship in Entity Framework: Why foreign key value is null?
- Linq to format a list of items to replace foreach loop
- How do I combine two Expressions?
- Joining Linq tables using classes C# WPF Linq
- System.Linq.Expressions with computed column
- skipWhile in LINQ is not working as excepted