DbContextCRUDExtensions 1.0.8
See the version list below for details.
dotnet add package DbContextCRUDExtensions --version 1.0.8
NuGet\Install-Package DbContextCRUDExtensions -Version 1.0.8
<PackageReference Include="DbContextCRUDExtensions" Version="1.0.8" />
paket add DbContextCRUDExtensions --version 1.0.8
#r "nuget: DbContextCRUDExtensions, 1.0.8"
// Install DbContextCRUDExtensions as a Cake Addin #addin nuget:?package=DbContextCRUDExtensions&version=1.0.8 // Install DbContextCRUDExtensions as a Cake Tool #tool nuget:?package=DbContextCRUDExtensions&version=1.0.8
DbContext Create and Search Extensions
This is a .Net Core package for dealing with creating and searching entities with EFCore Version 7.0.9.
Example Project
You can view examples of each of these methods and different ways to use them in this repository.
Installation
CLI
dotnet add package DbContextCRUDExtensions --version <version_number>
Nuget Package Manager
- Search DBContextCRUDExtensions
- Select projects to install to and version number to install
- Click Install
DBContext Extension Methods
Method Name | Description |
---|---|
CreateEntityAsync | Creates an entity asynchronously |
CreateEntity | Creates an entity synchronously |
Search | Searches the database synchrnously |
SearchAsync | Searches the database asynchrnously |
CreateEntityAsync
This method creates an entity and automatically adds it to the DBContext change tracker and returns the entity created.
CreateEntityAsync has two overloads.
Both overloads take in 2 type parameters
- The Entity you want to create
- The Data Transfer Object you wish to convert from
The first overload takes in 3 parameters
- The Data Transfer Object you wish to convert to an entity
- A Method that takes in an instance of your dto, and returns Task<Entity>. This version is awaitable in case you need to perform an asynchronous action in the conversion method.
- A boolean to indicate if you would like to save the change to the database. This defaults to
false
. SaveChanges should only be called once during a request. It is recommended to make all of the changes to your entities, and then save
The Second overload also takes in 3 parameters
- The Data Transfer Object you wish to convert to an entity
- A Method that takes in an instance of your dto, and returns the entity object
- A boolean to indicate if you would like to save the change to the database. This defaults to
false
. SaveChanges should only be called once during a request. It is recommended to make all of the changes to your entities, and then save
This method returns the entity that was created and added to the changetracker.
CreateEntity
This method creates an entity and automatically adds it to the DBContext change tracker and returns the entity created.
CreateEntity is a synchrnous method that takes in 2 type parameters
- The Entity you want to create
- The Data Transfer Object you wish to convert from
It also takes in 3 parameters
- The Data Transfer Object you wish to convert to an entity
- A Method that takes in an instance of your dto, and returns the entity object
- A boolean to indicate if you would like to save the change to the database. This defaults to
false
. SaveChanges should only be called once during a request. It is recommended to make all of the changes to your entities, and then save
This is just a synchrnous version of CreateEntityAsync.
SearchAsync
This method queries a database using given pagination and filter data. and returns a PageReturn object.
It takes in 3 type parameters
- Entity you wish to search through.
- The Data Transfer Object you want to convert the results to.
- The filter object you want to filter by.
It also takes in 4 parameters
- A PageAndFilter Object
- Method that takes in an object of you entity, and returns the dto you want to convert to.
- Method that takes in your filter object and an IQueryable of your entity type and returns an Iqueryable of your entity type. This can be null if you don't want to provide an implementation for this method. If null, no filters will be applied.
- A nullable string array to add your includes on your query for your navigation objects.
Search
This method is exactly the same as SearchAsync, but is synchronous. All type parameters and parameters are the same.
Enums
SortDirection
The only Enum in this package is the SortDirection
Enum. This enum has 2 values
- ASC (for Ascending)
- DSC (for Descending)
This can be used however you wish for sorting, but is implemented in this package in the search methods to determine what sort order to use on a given property.
Classes
Page
Page has 4 properties.
Type | Name | Description |
---|---|---|
int | PageNumber | Indicates which page number you want |
int | RecordsPerPage | Indicates how many records you want to return |
SortDirection | SortDirection | Is used to determine if the property is sorted in ascending or descending order |
string | SortField | Determines which field the resulting data will be sorted by |
This class has one constructor that sets PageNumber to 0, RecordsPerPage to 25, SortDirection to Ascending, and SortField to "Id"
PageAndFilter
PageAndFitler has 1 type parameter T.
- The class you want to use for your filter object.
PageAndFilter has 2 properties
Type | Name | Description |
---|---|---|
Page | Page | The Page object you want to use for paginating search results |
T | Filter | The Filter object you want to use for filtering search results |
PageAndFilter also has 4 shortcuts for properties on the Page object
Name | Return |
---|---|
PageNumber | Page.PageNumber |
RecordsPerPage | Page.RecordsPerPage |
SortDirection | Page.SortDirection |
SortField | Page.SortDirection |
PageReturn
This is the return object for both Search and SearchAsync methods.
PageReturn has 2 type parameters
- The Data Transfer Object
- The Filter object that you want to use.
PageReturn has 3 properties
Type | Name | Description |
---|---|---|
List | Data | The resulting data from a search |
int | TotalRecordCount | Total number of records that match filter, before pagination |
PageAndFilter | PageAndFilter | PageAndFilter object that was used for Search requests |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 7.0.9)
- System.Linq.Dynamic.Core (>= 1.3.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.