# Abp.Trees **Repository Path**: shqgroup_admin/Abp.Trees ## Basic Information - **Project Name**: Abp.Trees - **Description**: An abp module that provides standard tree structure entity implement. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-24 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Abp.Trees [![NuGet](https://img.shields.io/nuget/v/EasyAbp.Abp.Trees.Domain.Shared.svg?style=flat-square)](https://www.nuget.org/packages/EasyAbp.Abp.Trees.Domain.Shared) [![NuGet Download](https://img.shields.io/nuget/dt/EasyAbp.Abp.Trees.Domain.Shared.svg?style=flat-square)](https://www.nuget.org/packages/EasyAbp.Abp.Trees.Domain.Shared) [![GitHub stars](https://img.shields.io/github/stars/EasyAbp/Abp.Trees?style=social)](https://www.github.com/EasyAbp/Abp.Trees) An abp module that provides standard tree structure entity implement. ## Installation 1. Install the following NuGet packages. ([see how](https://github.com/EasyAbp/EasyAbpGuide/blob/master/How-To.md#add-nuget-packages)) * EasyAbp.Abp.Trees.Domain * EasyAbp.Abp.Trees.Domain.Shared * EasyAbp.Abp.Trees.EntityFrameworkCore ## Usage 1. Create a entity and implement `ITree`. 1. Create a Repository for the entity. `EfCoreTreeRepository` override some function of `EfCoreRepository` to match tree structure: * `InsertAsync` :Auto Append node `Code` and Calc `Level` property when insert * `UpdateAsync` :Auto Move node when update a `Entity` that parentId is modified * `DeleteAsync` :Also delete `Children` nodes 1. You have two ways to use this `Repository` * Way 1 : Default Repository(`ITreeRepository<>`), Add `context.Services.AddTreeRepository();` to ConfigureServices method in `MyProjectNameEntityFrameworkCoreModule.cs`. * Way 2 : Create a `CustomRepository` that base on `EfCoreTreeRepository` * Example: ```csharp context.Services.AddAbpDbContext(options => { options.AddDefaultRepositories(includeAllEntities: true);//add Abp's `IRepository` options.AddDefaultTreeRepositories();//add `ITreeRepository` for all Entity with implement `ITree` options.TreeEntity(x => x.CodeLength = 10);//set CodeLength for each Entity(Default:5) }); ``` ## Sample It works fine with `Volo.Abp.Application.Services.CrudAppService`. After replacing `IRepository<>` with `ITreeRepository`, the repository will handle the tree structure of the entity during creating, updating, and deleting. ```csharp public class OrganizationUnitAppService: Volo.Abp.Application.Services.CrudAppService< Domain.OrganizationUnit, Application.OrganizationUnitDto, Application.OrganizationUnitDto,Guid, Volo.Abp.Application.Dtos.IPagedAndSortedResultRequest, Application.CreateOrganizationUnitDto,Application.UpdateOrganizationUnitDto>, IOrganizationUnitAppService { public OrganizationUnitAppService( EasyAbp.Abp.Trees.ITreeRepository organizationUnitRepository ):base(organizationUnitRepository) { } } ``` ## Roadmap - [ ] Widget of tree operation for MVC UI. - [ ] Create a TreeManager to provides more function,example: `Sort`(reassigned code),` Ui Pagination`... - [ ] More Unit tests.