laget.Db.Dapper
1.3.42
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package laget.Db.Dapper --version 1.3.42
NuGet\Install-Package laget.Db.Dapper -Version 1.3.42
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.42" />
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.42
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: laget.Db.Dapper, 1.3.42"
#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.42
// Install laget.Db.Dapper as a Cake Tool
#tool nuget:?package=laget.Db.Dapper&version=1.3.42
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
laget.Db.Dapper
A repository pattern implementation for Dapper, a high-performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc...
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 | 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 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.
-
.NETStandard 2.0
- Dapper (>= 2.0.123)
- Microsoft.Data.SqlClient (>= 5.1.1)
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- System.ComponentModel.Annotations (>= 5.0.0)
-
.NETStandard 2.1
- Dapper (>= 2.0.123)
- Microsoft.Data.SqlClient (>= 5.1.1)
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- System.ComponentModel.Annotations (>= 5.0.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.6.71 | 78 | 6/3/2024 | |
1.6.70 | 104 | 4/5/2024 | |
1.6.69 | 207 | 3/4/2024 | |
1.6.68 | 192 | 2/9/2024 | |
1.6.67 | 122 | 1/20/2024 | |
1.6.65 | 84 | 1/19/2024 | |
1.6.64 | 83 | 1/19/2024 | |
1.6.63 | 113 | 1/8/2024 | |
1.6.62 | 153 | 12/6/2023 | |
1.6.61 | 121 | 11/22/2023 | |
1.6.60 | 113 | 11/10/2023 | |
1.6.59 | 90 | 11/10/2023 | |
1.5.58 | 96 | 11/10/2023 | |
1.5.57 | 115 | 11/6/2023 | |
1.5.56 | 160 | 10/2/2023 | |
1.5.55 | 145 | 9/4/2023 | |
1.5.54 | 153 | 7/3/2023 | |
1.5.53 | 143 | 6/29/2023 | |
1.4.45 | 134 | 6/13/2023 | |
1.3.42 | 135 | 5/26/2023 | |
1.3.41 | 180 | 4/4/2023 | |
1.3.40 | 175 | 4/3/2023 | |
1.2.39 | 223 | 3/10/2023 | |
1.2.38 | 214 | 3/10/2023 | |
1.1.27 | 276 | 2/6/2023 | |
1.1.23 | 295 | 12/5/2022 | |
1.1.22 | 327 | 11/7/2022 | |
1.1.19 | 416 | 8/22/2022 | |
1.1.17 | 413 | 6/7/2022 | |
1.1.16 | 467 | 3/7/2022 | |
1.1.15 | 412 | 2/7/2022 | |
1.1.14 | 276 | 12/21/2021 | |
1.1.13 | 303 | 11/28/2021 | |
1.1.12 | 317 | 11/10/2021 | |
1.1.11 | 318 | 11/10/2021 | |
1.1.9 | 505 | 10/4/2021 | |
1.1.8 | 453 | 8/23/2021 | |
1.1.7 | 383 | 8/16/2021 | |
1.1.6 | 345 | 7/7/2021 | |
1.1.5 | 361 | 7/5/2021 | |
1.1.4 | 366 | 6/28/2021 | |
1.1.2 | 385 | 6/7/2021 | |
1.1.1 | 361 | 5/21/2021 | |
1.0.18 | 398 | 5/3/2021 | |
1.0.17 | 390 | 4/6/2021 | |
1.0.16 | 375 | 3/5/2021 | |
1.0.15 | 431 | 2/11/2021 | |
1.0.14 | 383 | 2/1/2021 | |
1.0.13 | 551 | 1/8/2021 | |
1.0.12 | 392 | 1/8/2021 | |
1.0.11 | 456 | 1/1/2021 | |
1.0.10 | 466 | 12/23/2020 | |
1.0.9 | 375 | 12/22/2020 | |
1.0.8 | 436 | 12/22/2020 | |
1.0.7 | 355 | 12/22/2020 | |
1.0.6 | 444 | 12/16/2020 | |
1.0.5 | 456 | 12/9/2020 | |
1.0.4 | 388 | 12/8/2020 | |
1.0.3 | 371 | 12/8/2020 | |
1.0.2 | 367 | 12/8/2020 | |
1.0.1 | 389 | 12/8/2020 |