|
1 | 1 | # Entity Framework Base Package |
2 | 2 |
|
3 | | -This NuGet package contains a base entity definition along with an entity service which handles the update, soft delete, add etc. which automatically sets the properties on the base entity and does some basic validation. Every class is extendable, so you can fit it to your needs. The `Add`, `Delete`, `Update`, and `Restore` functions on the entity service are all `virtual`, so you can extend them to fit your needs if you e.g. need more base attributes set automatically. |
| 3 | +This NuGet package contains a base entity definition along with an entity service which handles the update, delete, add etc. which automatically sets the properties on the base entity and does some basic validation. Every class is extendable, so you can fit it to your needs. The `Add`, `Delete`, `Update`, and `Restore` functions on the entity services are all `virtual`, so you can extend them to fit your needs if you e.g. need more base attributes set automatically. |
4 | 4 |
|
5 | | -## BaseEntity |
| 5 | +The class `BaseEntity` is for hard delete entities while `BaseSoftDeleteEntity` is for entities which are only soft deleted. There are repositories for each type of entity as well with mostly the same functionality although the soft delete version has a few extra parameters and also has a restore function. |
| 6 | + |
| 7 | +## Entities |
| 8 | + |
| 9 | +### BaseEntity |
6 | 10 | The base entity contains the following properties: |
7 | 11 |
|
8 | 12 | | Name | Type | Description | |
9 | 13 | | ---- | ---- | ----------- | |
10 | 14 | | Id | Guid? | The unique id of the entity | |
11 | 15 | | Created | DateTime | The UTC time for when this entity was created | |
12 | 16 | | Updated | DateTime | The UTC time for when this entity was last updated | |
| 17 | + |
| 18 | +### BaseSoftDeleteEntities |
| 19 | +This class extends `BaseEntity` and adds the following properties: |
| 20 | + |
| 21 | +| Name | Type | Description | |
| 22 | +| ---- | ---- | ----------- | |
13 | 23 | | DeletedAt | DateTime? | The UTC time for when this entity was soft deleted | |
14 | 24 | | Deleted | bool | Whether the entity is deleted or not | |
15 | 25 |
|
16 | | -## EntityRepository |
| 26 | +## Repositories |
| 27 | + |
| 28 | +### EntityRepository |
17 | 29 | This is the entity service which handles the communication with the database. There is also an interface `IEntityRepository`, so you can use DI to inject it into your code. |
18 | 30 |
|
19 | 31 | | Function | Description | |
20 | 32 | | -------- | ----------- | |
21 | 33 | | Get | Fetch a single entity | |
22 | 34 | | GetList | Get a filtered and possibly paginated list of entities | |
| 35 | +| GetListWithSelect | Get a filtered and possibly paginated list of entities where you can specify what properties to return | |
23 | 36 | | Add | Add a new entity to the DB. The function automatically sets `Created`, `Updated`, and `Id` on the entity | |
24 | 37 | | Update | Update the provided entity in the DB. The function automatically sets `Updated` | |
| 38 | +| Delete | Removes the entity from the DB | |
| 39 | + |
| 40 | +### EntitySoftDeleteRepository |
| 41 | +This entity repository handles soft delete entities. It implements the interface `IEntitySoftDeleteRepository` for DI purposes. |
| 42 | + |
| 43 | +For each method in `EntityRepository` where relevant, there are extra parameters for handling soft delete entities e.g. `GetList` where you can choose whether to include deleted in the result list or not (not by default). |
| 44 | + |
| 45 | +Along with the methods from `EntityRepository`, this repository implements the following extra methods along with changed behaviour on `Delete`: |
| 46 | + |
| 47 | +| Function | Description | |
| 48 | +| -------- | ----------- | |
25 | 49 | | Delete | Soft delete the entity. Sets `Deleted` to `true` and sets `Deleted` as well | |
26 | 50 | | Restore | Undelete the entity. Sets `Deleted` to `false` and sets `DeletedAt` to `null` | |
0 commit comments