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>();
}