Dapper.Builder.Autofac 0.1.0

Dapper Builder support for Autofac

Install-Package Dapper.Builder.Autofac -Version 0.1.0
dotnet add package Dapper.Builder.Autofac --version 0.1.0
<PackageReference Include="Dapper.Builder.Autofac" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dapper.Builder.Autofac --version 0.1.0
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)

NuGet
NuGet

Build Status

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!

License

All contents of this package are licensed under the MIT license.

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)

NuGet
NuGet

Build Status

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!

License

All contents of this package are licensed under the MIT license.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.1.0 53 9/24/2019
0.0.26 43 9/16/2019
0.0.24 62 9/9/2019
0.0.23 51 9/8/2019
0.0.22 47 9/4/2019
0.0.21 40 9/4/2019
0.0.20 39 9/4/2019
0.0.19 51 8/29/2019
0.0.18 44 8/28/2019
0.0.17 43 8/28/2019
0.0.15 46 8/28/2019
0.0.14 45 8/26/2019
0.0.13 52 8/25/2019
0.0.12 47 8/25/2019
0.0.11 52 8/17/2019
0.0.10 52 8/17/2019
0.0.9 63 6/21/2019
0.0.8 62 6/21/2019
0.0.7 60 6/21/2019
0.0.6 64 6/21/2019
0.0.3 82 5/21/2019
0.0.2 81 5/21/2019