Skip to content

Simple package make easy a fluent execution on database connection by dapper

License

Notifications You must be signed in to change notification settings

AugustoDeveloper/dapper-fluent-execution

Repository files navigation

Dapper - Fluent Execution

dapper-fluent-execution NuGet Nuget

This package is a simple, easy and fluent way to execute SQL on database connection by Dapper.

Installation

You can install the package using one of the options bellow:

  • Package Manager
PM> NuGet\Install-Package Dapper.FluentExecution -Version 0.2.0
  • .NET CLI
dotnet add package Dapper.FluentExecution --version 0.2.0
  • PackageReference
<PackageReference Include="Dapper.FluentExecution" Version="0.2.0" />

Usage

Simple query:

public async Task<List<Person>> GetAllAsync(CancellationToken cancellation = default)
    => await "SELECT * FROM Persons"
        .On(DatabaseConnection)
        .QueryAsync<Person>(cancellation)
        .ToListAsync();

Querying with parameter:

public async Task<Person?> GetByIdAsync(int id, CancellationToken cancellation = default)
    => await "SELECT * FROM Persons where Id = @Id"
        .On(DatabaseConnection)
        .WithParameter("@Id", id)
        .QuerySingleOrDefaultAsync<Person>(cancellation);

Querying with conditional parameter and append:

public async Task<Person?> GetByIdAsync(int id, int? specificAddressId, CancellationToken cancellation = default)
    => await "SELECT p.* FROM Persons p inner join Addresses a on a.PersonId = p.Id where Id = @Id"
        .On(DatabaseConnection)
        .AppendSql(specificAddressId.HasValue, "AND a.Id = @AddressId")
        .WithParameter(specificAddressId.HasValue, "@AddressId", specificAddressId)
        .WithParameter("@Id", id)
        .QuerySingleOrDefaultAsync<Person>(cancellation);

Release - v0.2.0

  • Add summary doc on all .cs files
  • Add suport to Execution methods on IExecutionBuilder. E.g.: Execute, ExecuteAsync, ExecuteScalar, ExecuteScalarAsync....
  • Add support to dynamic parameter by dynamic object. E.g.: new { Param1 = "1", Param2 = 2 }
  • Add support to set command timeout
  • Add support to set query as an execution of stored procedure
  • Add QueryAsync, Query,... an IEnumerable<T> result

Release - v0.1.1

  • Fixing csproj documentation to Nuget.org

Release - v0.1.0

  • Methods to query directly from a string by fluent builder
  • Adding support to add SqlDbType parameters

About

Simple package make easy a fluent execution on database connection by dapper

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages