Gleeman.Repository.Dapper 7.0.0

dotnet add package Gleeman.Repository.Dapper --version 7.0.0                
NuGet\Install-Package Gleeman.Repository.Dapper -Version 7.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gleeman.Repository.Dapper" Version="7.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gleeman.Repository.Dapper --version 7.0.0                
#r "nuget: Gleeman.Repository.Dapper, 7.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Gleeman.Repository.Dapper as a Cake Addin
#addin nuget:?package=Gleeman.Repository.Dapper&version=7.0.0

// Install Gleeman.Repository.Dapper as a Cake Tool
#tool nuget:?package=Gleeman.Repository.Dapper&version=7.0.0                

Gleeman.Repository.Dapper

Command Repositories

Create
public interface IDapperCreateAsyncRepository<TEntity>
    where TEntity : class
{
    Task<TEntity> CreateAsync(TEntity parameter, string sql);
    Task InsertAsync(TEntity parameter, string sql);
    Task<IEnumerable<TEntity>> CreateRangeAsync(IEnumerable<TEntity> parameters, string sql);
    Task InsertRangeAsync(IEnumerable<TEntity> parameters, string sql);
}
public interface IDapperCreateSyncRepository<TEntity>
{
    TEntity Create(TEntity parameter, string sql);
    void Insert(TEntity parameter, string sql);
    IEnumerable<TEntity> CreateRange(IEnumerable<TEntity> parameters, string sql);
    void InsertRange(IEnumerable<TEntity> parameters, string sql);
}
Delete
public interface IDapperDeleteAsyncRepository<TEntity>
    where TEntity : class
{
    Task RemoveAsync(string sql);
    Task RemoveRangeAsync(string sql);
}
public interface IDapperDeleteSyncRepository<TEntity>
    where TEntity : class
{
    void Remove(string sql);
    void RemoveRange(string sql);
}
Update
public interface IDapperUpdateAsyncRepository<TEntity>
    where TEntity : class
{
    Task<TEntity> UpdateAsync(TEntity parameter, string sql);
    Task EditAsync(TEntity parameter, string sql);
    Task<IEnumerable<TEntity>> UpdateRangeAsync(IEnumerable<TEntity> parameters, string sql);
    Task EditRangeAsync(IEnumerable<TEntity> parameters, string sql);
}
public interface IDapperUpdateSyncRepository<TEntity>
        where TEntity : class
    {
        TEntity Update(TEntity parameter, string sql);
        void Edit(TEntity parameter, string sql);
        IEnumerable<TEntity> UpdateRange(IEnumerable<TEntity> parameters, string sql);
        void EditRange(IEnumerable<TEntity> parameters, string sql);
    }

Query Repositories

public interface IDapperQueryAsyncRepository<TEntity>
    where TEntity : class
{

    Task<IEnumerable<TEntity>> ReadAllAsync(string sql, Action<Pagination> pagination = null);

    Task<TEntity> ReadSingleOrDefaultAsync(string sql);

    Task<TEntity> ReadFirstOrDefaultAsync(string sql);

    Task<TEntity> ReadLastOrDefaultAsync(string sql);

    Task<TEntity> ReadFirstAsync(string sql);

    Task<TEntity> ReadLastAsync(string sql);

    Task<TEntity> ReadSingleAsync(string sql);
}
public interface IDapperQuerySyncRepository<TEntity>
    where TEntity : class
{
    IEnumerable<TEntity> ReadAll(string sql, Action<Pagination> pagination = null);

    TEntity ReadSingleOrDefault(string sql);

    TEntity ReadFirstOrDefault(string sql);

    TEntity ReadLastOrDefault(string sql);

    TEntity ReadFirst(string sql);

    TEntity ReadLast(string sql);

    TEntity ReadSingle(string sql);
}

EXAMPLE

Program.cs
using Gleeman.Repository.Dapper.Configuration;
builder.Services.AddDapperRepository(option =>
{
    option.ConnectionString = "Server=(localdb)/MSSQLLocalDB;Database=EmployeeDB;Trusted_Connection=True;";
});
public interface IEmployeeCommandRepository:IDapperCreateAsyncRepository<Employee>
{
}

public class EmployeeCommandRepository:DapperCommandRepository<Employee>,IEmployeeCommandRepository
{

}

[Route("api/[controller]")]
[ApiController]
public class EmployeesController : ControllerBase
{
    private readonly IEmployeeCommandRepository _command;

    public EmployeesController(IEmployeeCommandRepository command)
    {
        _command = command;
    }

    [HttpPost]
    public async Task<IActionResult>CreateEmployee(Employee employee)
    {
        string sql= "INSERT INTO Companies (CompanyName, CompanyAddress, Country,GlassdoorRating) VALUES (@Name, @Salary)";

        var parameters = new DynamicParameters();
        parameters.Add("Name", employee.Name, DbType.String);
        parameters.Add("Salary", employee.Salary, DbType.Decimal);
        var result = await _command.CreateAsync(employee,sql);
        return Created("", result);
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
7.0.0 274 10/23/2023