laget.Db.Dapper 1.3.40

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package laget.Db.Dapper --version 1.3.40                
NuGet\Install-Package laget.Db.Dapper -Version 1.3.40                
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="laget.Db.Dapper" Version="1.3.40" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add laget.Db.Dapper --version 1.3.40                
#r "nuget: laget.Db.Dapper, 1.3.40"                
#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 laget.Db.Dapper as a Cake Addin
#addin nuget:?package=laget.Db.Dapper&version=1.3.40

// Install laget.Db.Dapper as a Cake Tool
#tool nuget:?package=laget.Db.Dapper&version=1.3.40                

laget.Db.Dapper

A repository pattern implementation for Dapper, a high-performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc...

Nuget Nuget

Configuration

This example is shown using Autofac since this is the go-to IoC for us.

public class DatabaseModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.Register(c => new DapperDefaultProvider(c.Resolve<IConfiguration>().GetConnectionString("SqlConnectionString"))).As<IDapperDefaultProvider>().SingleInstance();
    }
}
public class DatabaseModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.Register(c => new DapperDefaultProvider(c.Resolve<IConfiguration>().GetConnectionString("SqlConnectionString"), new MemoryCacheOptions
            {
                CompactionPercentage = 0.25,
                ExpirationScanFrequency = TimeSpan.FromMinutes(5),
                SizeLimit = 1024
            })).As<IDapperDefaultProvider>().SingleInstance();
    }
}

Usage

  • Repository
  • CachedRepository
  • ReadOnlyRepository

Built-in methods

public interface IRepository<TEntity>
{
    IEnumerable<TEntity> Find();
    Task<IEnumerable<TEntity>> FindAsync();
    TEntity Get(int id);
    Task<TEntity> GetAsync(int id);

    int Insert(TEntity entity);
    Task<int> InsertAsync(TEntity entity);

    void Update(TEntity entity);
    Task UpdateAsync(TEntity entity);

    void Delete(TEntity entity);
    Task DeleteAsync(TEntity entity);
}

Generic

public interface IUserRepository : IRepository<Models.User>
{
}

public class UserRepository : Repository<Models.User>, IUserRepository
{
    public UserRepository(IDapperDefaultProvider provider)
        : base(provider)
    {
    }
}

Caching

public interface IUserRepository : IRepository<Models.User>
{
}

public class UserRepository : Repository<Models.User>, IUserRepository
{
    public UserRepository(IDapperDefaultProvider provider)
        : base(provider)
    {
    }
    
    public override Models.User Get(int id)
    {
        var cacheKey = "_Id_" + id;
        var item = CacheGet<Models.User>(cacheKey);

        if (item != null)
            return item;

        using (var connection = new SqlConnection(ConnectionString))
        {
            var sql = $@"
                SELECT * FROM [{TableName}]
                WHERE Id = @id";

            var parameters = new
            {
                id
            };

            var result = connection.QueryFirstOrDefault<Models.User>(sql, parameters);

            CacheAdd(cacheKey, result);

            return result;
        }
    }
}
Product 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 is compatible. 
.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.

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.6.72 90 9/3/2024
1.6.71 90 6/3/2024
1.6.70 125 4/5/2024
1.6.69 215 3/4/2024
1.6.68 198 2/9/2024
1.6.67 132 1/20/2024
1.6.65 93 1/19/2024
1.6.64 93 1/19/2024
1.6.63 136 1/8/2024
1.6.62 174 12/6/2023
1.6.61 126 11/22/2023
1.6.60 118 11/10/2023
1.6.59 113 11/10/2023
1.5.58 102 11/10/2023
1.5.57 121 11/6/2023
1.5.56 166 10/2/2023
1.5.55 150 9/4/2023
1.5.54 157 7/3/2023
1.5.53 147 6/29/2023
1.4.45 138 6/13/2023
1.3.42 137 5/26/2023
1.3.41 187 4/4/2023
1.3.40 179 4/3/2023
1.2.39 224 3/10/2023
1.2.38 217 3/10/2023
1.1.27 281 2/6/2023
1.1.23 299 12/5/2022
1.1.22 333 11/7/2022
1.1.19 422 8/22/2022
1.1.17 418 6/7/2022
1.1.16 473 3/7/2022
1.1.15 415 2/7/2022
1.1.14 278 12/21/2021
1.1.13 305 11/28/2021
1.1.12 320 11/10/2021
1.1.11 321 11/10/2021
1.1.9 510 10/4/2021 1.1.9 is deprecated because it has critical bugs.
1.1.8 459 8/23/2021 1.1.8 is deprecated because it has critical bugs.
1.1.7 389 8/16/2021 1.1.7 is deprecated because it has critical bugs.
1.1.6 349 7/7/2021
1.1.5 364 7/5/2021
1.1.4 371 6/28/2021
1.1.2 389 6/7/2021
1.1.1 365 5/21/2021
1.0.18 402 5/3/2021
1.0.17 392 4/6/2021
1.0.16 377 3/5/2021
1.0.15 435 2/11/2021
1.0.14 387 2/1/2021
1.0.13 556 1/8/2021
1.0.12 396 1/8/2021
1.0.11 460 1/1/2021
1.0.10 469 12/23/2020
1.0.9 378 12/22/2020
1.0.8 439 12/22/2020
1.0.7 360 12/22/2020
1.0.6 448 12/16/2020
1.0.5 461 12/9/2020
1.0.4 391 12/8/2020
1.0.3 375 12/8/2020
1.0.2 371 12/8/2020
1.0.1 392 12/8/2020