Dapper.Builder.Core
1.3.1
dotnet add package Dapper.Builder.Core --version 1.3.1
NuGet\Install-Package Dapper.Builder.Core -Version 1.3.1
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="Dapper.Builder.Core" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dapper.Builder.Core --version 1.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Dapper.Builder.Core, 1.3.1"
#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 Dapper.Builder.Core as a Cake Addin
#addin nuget:?package=Dapper.Builder.Core&version=1.3.1
// Install Dapper.Builder.Core as a Cake Tool
#tool nuget:?package=Dapper.Builder.Core&version=1.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Dapper.Builder
The library offers a fluent builder way to create queries with Dapper. This includes joins, sub queries with multiple database support (SQL, Postgre, Snowflake, Sqlite)
Installation
Autofac
Install-Package Dapper.Builder.Autofac
Core
dotnet add package Dapper.Builder.Core
.Net Core Setup
services.AddDapperBuilder(
new CoreBuilderConfiguration
{
DatabaseType = DatabaseType.SQL,
DbConnectionFactory = (ser) => new SqlConnection("server=(local)")
});
Autofac Setup
builder.RegisterModule(new DapperBuilderModule(new AutofacBuilderConfiguration() {
DatabaseType = DatabaseType.SQL,
DbConnectionFactory = (ser) => new SqlConnection("server=(local)")
}));
Usage
Injection
public class SomeRepository : ISomeRepository {
private readonly IQueryBuilder<SomeClass> _query;
public SomeRepository (IQueryBuilder<SomeClass> query) { _query = query; }
Simple Query
public async Task<IEnumerable<SomeClass>> GetSomeSimpleStuff () {
return await _query.Columns (
nameof (SomeClass.SomeColumnId),
nameof (SomeClass.AnotherColumn))
.Where (sc => sc.Date < DateTime.Now.AddDays (-5))
.SortDescending (sc => sc.CreatedDate).ExecuteAsync ();
}
Query with join and sub query on itself
public async Task<IEnumerable<SomeClass>> GetSomeComplexStuff () {
return await _query.
.SubQuery<SomeOtherClass> (q =>
q.Columns (nameof (SomeOtherClass.Id))
.Alias ("soc")
.Top (1)
.ParentAlias<SomeClass> ("sc")
.Where<SomeClass> ((sc, soc) => sc.SomeId == soc.SomeOtherId)
, "SubQueryAlias1")
.SubQuery<SomeOtherClass> (q =>
q.Top (1)
.Columns (nameof (SomeOtherClass.Amount))
.Alias ("soc")
.ParentAlias<SomeClass> ("sc")
, "SubQueryAlias2")
.Alias ("sc")
.Join<SomeOtherOtherClass> (((sc, sooc) => sooc.SomeClassId == sc.Id))
.GroupBy ((sc) => sc.SomeId).ExecuteAsync();
}
Why a fluent builder?
The same reason why IQueryable exists. So you could pass this along to other methods, add whatever you want to it and then execute when you are finished.
public async Task UpdateAdminData(IUser user)
queryBuilder.Top(20);
if(user is IAdmin){
ApplyAdminPipes(queryBuilder);
} else {
ApplyUserPipes(queryBuilder);
}
await queryBuilder.ExecuteUpdateAsync(user);
}
Road Map
- Better Alias Support
- More Database Support
- Dapper has no out of the box support for Snowflake and their driver has no support for Dapper.
- Aggregations - ie. sum, max, min, etc.
- More methods to implement.
Contributors
Contribute
Contributions to the package are always welcome!
- Report any bugs or issues you find on the issue tracker.
- You can grab the source code at the package's git repository.
License
All contents of this package are licensed under the MIT license.
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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Dapper (>= 2.0.4)
- FastMember (>= 1.5.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.0.0)
- System.Text.Json (>= 4.6.0)
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 |
---|---|---|
1.3.1 | 5,249 | 8/2/2020 |
1.3.0 | 505 | 5/19/2020 |
0.2.9 | 427 | 5/15/2020 |
0.2.8 | 408 | 5/14/2020 |
0.2.7 | 405 | 5/14/2020 |
0.2.6 | 407 | 5/14/2020 |
0.2.5 | 440 | 5/5/2020 |
0.2.4 | 619 | 4/4/2020 |
0.2.3 | 920 | 11/14/2019 |
0.2.2 | 487 | 11/14/2019 |
0.2.1 | 465 | 11/13/2019 |
0.2.0 | 453 | 11/13/2019 |
0.1.0 | 504 | 9/24/2019 |
0.0.26 | 465 | 9/16/2019 |
0.0.25 | 470 | 9/16/2019 |
0.0.24 | 454 | 9/9/2019 |
0.0.23 | 486 | 9/8/2019 |
0.0.22 | 471 | 9/4/2019 |
0.0.21 | 451 | 9/4/2019 |
0.0.19 | 528 | 8/29/2019 |
0.0.18 | 493 | 8/28/2019 |
0.0.17 | 485 | 8/28/2019 |
0.0.16 | 504 | 8/28/2019 |
0.0.15 | 482 | 8/28/2019 |
0.0.14 | 471 | 8/26/2019 |
0.0.13 | 494 | 8/25/2019 |
0.0.12 | 486 | 8/25/2019 |
0.0.11 | 494 | 8/17/2019 |
0.0.10 | 496 | 8/17/2019 |
0.0.9 | 529 | 6/21/2019 |
0.0.8 | 513 | 6/21/2019 |
0.0.7 | 479 | 6/21/2019 |
0.0.6 | 501 | 6/21/2019 |
0.0.3 | 560 | 5/22/2019 |
0.0.1 | 571 | 5/21/2019 |