This package is a simple, easy and fluent way to execute SQL on database connection by Dapper.
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" />
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);
- Add summary doc on all .cs files
- Add suport to
Execution
methods onIExecutionBuilder
. 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,...
anIEnumerable<T>
result
- Fixing
csproj
documentation to Nuget.org
- Methods to query directly from a string by fluent builder
- Adding support to add
SqlDbType
parameters