72
1
// Entity Framework Classic
2
// Doc: https://entityframework-classic.net/to-self-hierarchy-list
3
4
// @nuget: Z.EntityFramework.Classic
5
6
using System;
7
using System.Collections.Generic;
8
using System.Data.Entity;
9
using System.Linq;
10
11
public class Program
12
{
13
public static void Main()
14
{
15
SeedEmployee();
16
17
using (var context = new EntityContext())
18
{
19
// The CEO will not be retrieved
20
var employees = context.Employees.Where(x => x.Name.StartsWith("Employee_"))
21
.ToSelfHierarchyList(x => x.Boss, options =>
22
options.MaxRecursion = 1);
23
24
FiddleHelper.WriteTable("1 - Employee", employees);
Cached Result