laget.Db.Dapper 1.6.70

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.70
NuGet\Install-Package laget.Db.Dapper -Version 1.6.70
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.70" />
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.70
#r "nuget: laget.Db.Dapper, 1.6.70"
#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.70

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

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.70 89 4/5/2024
1.6.69 201 3/4/2024
1.6.68 188 2/9/2024
1.6.67 118 1/20/2024
1.6.65 81 1/19/2024
1.6.64 79 1/19/2024
1.6.63 110 1/8/2024
1.6.62 149 12/6/2023
1.6.61 117 11/22/2023
1.6.60 110 11/10/2023
1.6.59 87 11/10/2023
1.5.58 92 11/10/2023
1.5.57 111 11/6/2023
1.5.56 156 10/2/2023
1.5.55 141 9/4/2023
1.5.54 149 7/3/2023
1.5.53 139 6/29/2023
1.4.45 131 6/13/2023
1.3.42 131 5/26/2023
1.3.41 176 4/4/2023
1.3.40 172 4/3/2023
1.2.39 219 3/10/2023
1.2.38 211 3/10/2023
1.1.27 271 2/6/2023
1.1.23 291 12/5/2022
1.1.22 325 11/7/2022
1.1.19 414 8/22/2022
1.1.17 411 6/7/2022
1.1.16 463 3/7/2022
1.1.15 410 2/7/2022
1.1.14 274 12/21/2021
1.1.13 301 11/28/2021
1.1.12 316 11/10/2021
1.1.11 317 11/10/2021
1.1.9 502 10/4/2021
1.1.8 451 8/23/2021
1.1.7 382 8/16/2021
1.1.6 343 7/7/2021
1.1.5 360 7/5/2021
1.1.4 364 6/28/2021
1.1.2 384 6/7/2021
1.1.1 359 5/21/2021
1.0.18 396 5/3/2021
1.0.17 388 4/6/2021
1.0.16 373 3/5/2021
1.0.15 429 2/11/2021
1.0.14 382 2/1/2021
1.0.13 548 1/8/2021
1.0.12 391 1/8/2021
1.0.11 455 1/1/2021
1.0.10 463 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