huzcodes.Persistence
1.2.0
See the version list below for details.
dotnet add package huzcodes.Persistence --version 1.2.0
NuGet\Install-Package huzcodes.Persistence -Version 1.2.0
<PackageReference Include="huzcodes.Persistence" Version="1.2.0" />
paket add huzcodes.Persistence --version 1.2.0
#r "nuget: huzcodes.Persistence, 1.2.0"
// Install huzcodes.Persistence as a Cake Addin #addin nuget:?package=huzcodes.Persistence&version=1.2.0 // Install huzcodes.Persistence as a Cake Tool #tool nuget:?package=huzcodes.Persistence&version=1.2.0
huzcodes.Persistence
huzcodes.Persistence is a C# .NET 8 package designed to simplify data persistence operations for SQL and Oracle databases. It provides a set of functions for reading and inserting data, with support for both synchronous and asynchronous operations.
Installation
To install huzcodes.Persistence, use the following command in the Package Manager Console:
dotnet add package huzcodes.Persistence --version 1.0.0
Usage
To use huzcodes.Persistence, first inject the 'IDataProvider' interface into your class constructor. Then, you can use the provided functions to interact with your database. And to use huzcodes.Persistence Repository, first inject the 'IRepository<your entity model>' interface into your class constructor. Then, you can use the provided functions to interact with your database.
Registering the Package
// Add the registration of persistence from inside huzcodes persistence plugin
builder.Services.AddPersistenceServices();
// Add the registration of persistence using repository inside huzcodes persistence plugin.
// Before this step you need to create a class that inject your AppDbContext and inherits from 'HuzcodesRepository',
// then register it. For example let's call this class 'DbRepository'.
builder.Services.AddScoped(typeof(IRepository<>), typeof(DbRepository<>));
builder.Services.AddScoped(typeof(IReadRepository<>), typeof(DbRepository<>));
Reading Data Examples
SQL Reading Async Without Parameters
var data = await _dataProvider.LoadDataAsync<DataModel, dynamic>(readProcedureName, connectionStringKey, storageProvider: DataStorageProvider.Sql);
return Ok(data);
SQL Reading Async Without Parameters Using Repository
var oData = await _repository.ListAsync();
return Ok(oData);
SQL Reading Async With Parameters
var parameter = new { Id = id };
var data = await _dataProvider.LoadDataAsync<DataModel, dynamic>(readProcedureName, connectionStringKey, parameter);
return Ok(data.FirstOrDefault());
SQL Reading Async With Parameters Using Repository
var oResult = await _repository.GetByIdAsync(id);
return Ok(oResult);
SQL Reading Async With Parameters Using Repository and Specifications
var readByIdSpecification = new ReadByIdSpecifications(id);
var oResult = await _repository.FirstOrDefaultAsync(readByIdSpecification);
return Ok(oResult);
Oracle Reading Async Without Parameters
var data = await _dataProvider.LoadDataAsync<DataModel, dynamic>(readProcedureName, connectionStringKey, storageProvider: DataStorageProvider.Oracle);
return Ok(data);
Oracle Reading Async With Parameters
var parameter = new OracleDynamicParameters();
parameter.Add("Id", id, OracleMappingType.Int32, ParameterDirection.Input);
parameter.Add("DataResult", OracleMappingType.RefCursor, ParameterDirection.Output);
var data = await _dataProvider.LoadDataAsync<DataModel, dynamic>(readProcedureName, connectionStringKey, parameter, DataStorageProvider.Oracle);
return Ok(data.FirstOrDefault());
Inserting Data Examples
SQL Inserting Async
var parameter = new
{
Id = dataModel.Id,
ProductCreationDate = dataModel.Date,
PriceWithoutTax = dataModel.PriceWithoutTax,
ProductName = dataModel.ProductName
};
await _dataProvider.ExecuteDataAsync(createProcedureName, parameter, connectionStringKey);
return Ok();
SQL Inserting Async Using Repository
var oData = new DataModel()
{
Id = dataModel.Id,
Date = dataModel.Date,
PriceWithoutTax = dataModel.PriceWithoutTax,
ProductName = dataModel.ProductName
};
await _repository.AddAsync(oData);
return Ok();
Oracle Inserting Async
var parameter = new OracleDynamicParameters();
parameter.Add("Id", dataModel.Id, OracleMappingType.Int32, ParameterDirection.Input);
parameter.Add("ProductCreationDate", dataModel.Date, OracleMappingType.Date, ParameterDirection.Input);
parameter.Add("PriceWithoutTax", dataModel.PriceWithoutTax, OracleMappingType.Decimal, ParameterDirection.Input);
parameter.Add("ProductName", dataModel.ProductName, OracleMappingType.Varchar2, ParameterDirection.Input);
await _dataProvider.ExecuteDataAsync(createProcedureName, parameter, connectionStringKey, storageProvider: DataStorageProvider.Oracle);
return Ok();
For more information on how to use huzcodes.Persistence, please refer to the API Package Tests.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Ardalis.Specification (>= 8.0.0)
- Ardalis.Specification.EntityFrameworkCore (>= 8.0.0)
- Dapper (>= 2.1.28)
- Dapper.Oracle (>= 2.0.3)
- Microsoft.Data.SqlClient (>= 5.2.0)
- Oracle.EntityFrameworkCore (>= 8.21.121)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
huzcodes.Persistence is a C# .NET 8 package that simplifies data persistence operations for SQL and Oracle databases. It provides functions for reading and inserting data, with support for both synchronous and asynchronous operations.
What's new?
------------
In this release the package will be supporting repository pattern for CRUD, together with Specifications.