Pull to refresh
2
0
Dmitry Pavlov @dmitry_pavlov

ASP.NET Core, Blazor, .NET Core, .NET, C#

Send message

Tree Structure in EF Core: How to configure a self-referencing table and use it

Reading time 4 min
Views 26K

One of the very common questions I am getting from .NET community is how to configure and use the tree structures in EF Core. This story is one of the possible ways to do it.


The common tree structures are file tree, categories hierarchy, and so on. Let it be folders tree for example. The entity class will be a Folder:


public class Folder
{
    public Guid Id { get; set; }
    public string Name { get; set; }      
    public Folder Parent { get; set; }
    public Guid? ParentId { get; set; }
    public ICollection<Folder> SubFolders { get; } = new List<Folder>();
}
Read more →
Total votes 1: ↑1 and ↓0 +1
Comments 1

Information

Rating
Does not participate
Location
Санкт-Петербург, Санкт-Петербург и область, Россия
Date of birth
Registered
Activity