GenericModel 1.1.1
Generic.RepositoryAsync.EFCore
Additional DetailsUpdate for Generic.RepositoryAsync.EFCore. This project it's no longer maintained.
Requires NuGet 2.2 or higher.
dotnet add package GenericModel --version 1.1.1
NuGet\Install-Package GenericModel -Version 1.1.1
<PackageReference Include="GenericModel" Version="1.1.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="GenericModel" Version="1.1.1" />
<PackageReference Include="GenericModel"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add GenericModel --version 1.1.1
#r "nuget: GenericModel, 1.1.1"
#addin nuget:?package=GenericModel&version=1.1.1
#tool nuget:?package=GenericModel&version=1.1.1
Generic Repository - RichDomain, Asp.Net Core 2.2
Initiative
This project has objective to made a CRUD more easily. Adding an extra layer of abstraction in application. This project has building using the best programmation pratices.
Principles used:
- Reactive progammation;
- SOLID principles.
This project is builded in asp.net core 2.2 and has the dependencies below:
- Microsoft.EntityFrameworkCore (>= 2.2.1)
This project is focused in rich domains (well so I understood at least).
Like or dislike, tell me and togheter make this project better. Come and be part of this project!
Link to this package on nuget.org. Link to repository
Version Notes
VERSION 1.0.6 - Notes:
* All repositories names was changed, now the are BaseRepository and IBaseRepository.
VERSION 1.0.9 - Notes:
* All Namespace of project was changed to make more easily and intuitive.
- BaseRepository
- Before: GenericModel.Action
- After: Generic.Repository.Base
- Pagination
- Before: GenericModel.Pagination
- After: Generic.Repository.Extension.Pagination
- BaseFilter
- Before: GenericModel.Filter
- After: Generic.Repository.Entity.IFilter
* BaseFilter are changed to interface new is IBaseFilter.
* Filter was changed to attend more methods in lambda.
VERSION 1.1.1 - Notes:
- BaseFilter
- Auto Generate lambda was changed to annotation attribute. Is not necessary anymore add names complement;
- Performance is improved.
DOCs
For implements this package, follow the steps:
Install package:
- Package Manager > Install-Package GenericModel -Version 1.0.9
- .Net CLI > dotnet add package GenericModel --version 1.0.9
- Paket CLI > paket add GenericModel --version 1.0.9
In your repository make this:
public class MyEntity: BaseRepository<MyEntity, IBaseFilter>, IBaseRepository<MyEntity, IBaseFilter>
{
//if has any code you implements here!!!
}
///On the Controller
...Controller code
private readonly MyEntity _model;
...ctor
pulic async MyEntity GetById(long id)
{
return await _model.GetByIdAsync(id);
}
....Controller code...
From version 1.1.1
Attention this
Now is not necessary the attibute has the same name of entity. After this version, for use auto generate lambda to filter is need make this:
//The entity is the same of above example.
//My Entity Filter
public class MyEntityFilter: IBaseFilter
{
[LambdaGenerate(MethodOption = LambdaMethod.GreaterThanOrEqual, EntityPropertyName="Id")]
public long CodeMin { get; set; }
[LambdaGenerate(MethodOption = LambdaMethod.LessThanOrEqual, MergeOption= LambdaMerge.Or, EntityPropertyName="Id")]
public long CodeMax { get; set; }
/// The name property have the same name of entity property. Because this is not necessary set the EntityPropertyName.
[LambdaGenerate(MethodOption = LambdaMethod.Contains)]
public string Name { get; set; }
}
//In Controller
public async Task<ActionResult<IEnumerable<MyEntity>>> GetFiltred([FromQuery]MyEntityFilter filter)
{
return await _model.Filter(filter).ToListAsync();
}
//Lambda Generated
// x => x.Id >= valueId && x.Id <= valueId || x.Name.Contains(valueName)
From version 1.0.9
Atention on this
- The filter property names need to be the same as the entity
Now this method can be generate lambda by names complements
If you add one this word below the generated lambda will attend this.
List words reserved to lambda methods:
- Equal
- Contains (only used in string types)
- GreaterThan
- LessThan
- GreaterThanOrEquals
- LessThanOrEquals
To use this words: IdEqual
Generated lambda: x ⇒ x.Id == value;
List words reserved to merge expressions:
- Or
- And
To use this words: IdEqualAnd
Generated lambda: x ⇒ x.Id == value && .....;
If none word reserved is informed on properties the method assumes the follow default values:
- word reserved to merge expressions : And
- word reserved to lambda methods: Equal
//The entity is the same of above example.
//My Entity Filter
public class MyEntityFilter: IBaseFilter
{
[FromQuery(Name="Id")]
public long IdEqualAnd {get; set;}
[FromQuery(Name="Name")]
public string NameContains {get; set;}
}
//In Controller
public async Task<ActionResult<IEnumerable<MyEntity>>> GetFiltred([FromQuery]MyEntityFilter filter)
{
return await _model.Filter(filter).ToListAsync();
}
//Lambda Generated
// x => x.Id == valueId && x.Name.Contains(valueName)
From version 1.0.6
To make a Pagination
JSON of BaseConfigurePagination
{
(int)page : 0,
(int) size : 0
(string) sort : "ASC"
(string) order : "Id"
}
JSON Page format
{
"content": [
{
Entity Array
}
],
"totalElements": 0,
"sort": "string",
"order": "string",
"size": 0,
"page": 0
}
...Controller Code
[HttpGet("Paginate")]
public Pagination<Category> GetPage([FromQuery]BaseConfigurePagination config)
{
return _model.GetAll().PaginateTo(config);
}
...more code...
Saving data on database:
//The entity is the same of first example.
//In Controller
... Controller code
private readonly MyEntity _model;
//...ctor and more code.....
public async Task<ActionResult<MyEntity>> PostAsync(MyEntity entity)
{
_model.Map(entity);
entity = await _model.CreateAsync();
return CreatedAtAction(nameof(GetByIdAsync), new { id = entity.Id }, entity);
}
Updating data:
//.....more code....
public async Task<ActionResult> PutAsync(long id, MyEntity entity)
{
if(id != entity.Id)
return BadRequest();
_model.Map(entity);
await _model.UpdateAsync();
return NoContent();
}
Delete data:
//...more code and finally...
public async Task<ActionResult> DeleteAsync(long id)
{
if (id < 1)
return BadRequest();
await _model.DeleteAsync(id);
return NoContent();
}
Here are the implemented package on project using web api.
Doubts or recommendations? Send me an e-mail: guilherme.lpcaixeta@gmail.com
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.2
- Microsoft.EntityFrameworkCore (>= 2.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|
V.1.1.1
* Update auto generation lambda;
* Add annotation attributes to make auto generation lambda;
* Improve perfomance.