laget.Db.Dapper 1.6.71

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package laget.Db.Dapper --version 1.6.71
NuGet\Install-Package laget.Db.Dapper -Version 1.6.71
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.6.71" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add laget.Db.Dapper --version 1.6.71
#r "nuget: laget.Db.Dapper, 1.6.71"
#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.6.71

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

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> List();
    Task<IEnumerable<TEntity>> ListAsync();

    IEnumerable<TEntity> Where(string conditions);
    Task<IEnumerable<TEntity>> WhereAsync(string conditions);

    TEntity Get(int id);
    Task<TEntity> GetAsync(int id);
    IEnumerable<TEntity> Get(int[] ids);
    Task<IEnumerable<TEntity>> GetAsync(int[] ids);
    
    TEntity Insert(TEntity entity);
    Task<TEntity> InsertAsync(TEntity entity);
    void Insert(IEnumerable<TEntity> entities);
    Task InsertAsync(IEnumerable<TEntity> entities);

    TEntity Update(TEntity entity);
    Task<TEntity> UpdateAsync(TEntity entity);
    void Update(IEnumerable<TEntity> entities);
    Task UpdateAsync(IEnumerable<TEntity> entities);

    void Delete(TEntity entity);
    Task DeleteAsync(TEntity entity);
    void Delete(IEnumerable<TEntity> entities);
    Task DeleteAsync(IEnumerable<TEntity> entities);
}

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 is compatible.  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 is compatible.  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.71 77 6/3/2024
1.6.70 103 4/5/2024
1.6.69 206 3/4/2024
1.6.68 191 2/9/2024
1.6.67 121 1/20/2024
1.6.65 83 1/19/2024
1.6.64 81 1/19/2024
1.6.63 112 1/8/2024
1.6.62 152 12/6/2023
1.6.61 120 11/22/2023
1.6.60 112 11/10/2023
1.6.59 89 11/10/2023
1.5.58 95 11/10/2023
1.5.57 113 11/6/2023
1.5.56 159 10/2/2023
1.5.55 144 9/4/2023
1.5.54 152 7/3/2023
1.5.53 142 6/29/2023
1.4.45 133 6/13/2023
1.3.42 134 5/26/2023
1.3.41 179 4/4/2023
1.3.40 174 4/3/2023
1.2.39 222 3/10/2023
1.2.38 213 3/10/2023
1.1.27 275 2/6/2023
1.1.23 294 12/5/2022
1.1.22 326 11/7/2022
1.1.19 415 8/22/2022
1.1.17 412 6/7/2022
1.1.16 464 3/7/2022
1.1.15 411 2/7/2022
1.1.14 275 12/21/2021
1.1.13 302 11/28/2021
1.1.12 316 11/10/2021
1.1.11 317 11/10/2021
1.1.9 504 10/4/2021
1.1.8 452 8/23/2021
1.1.7 382 8/16/2021
1.1.6 344 7/7/2021
1.1.5 360 7/5/2021
1.1.4 365 6/28/2021
1.1.2 384 6/7/2021
1.1.1 360 5/21/2021
1.0.18 397 5/3/2021
1.0.17 389 4/6/2021
1.0.16 374 3/5/2021
1.0.15 430 2/11/2021
1.0.14 382 2/1/2021
1.0.13 550 1/8/2021
1.0.12 391 1/8/2021
1.0.11 455 1/1/2021
1.0.10 465 12/23/2020
1.0.9 374 12/22/2020
1.0.8 435 12/22/2020
1.0.7 354 12/22/2020
1.0.6 443 12/16/2020
1.0.5 455 12/9/2020
1.0.4 387 12/8/2020
1.0.3 370 12/8/2020
1.0.2 366 12/8/2020
1.0.1 388 12/8/2020