laget.Db.Dapper
2.1.35.74
Prefix Reserved
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package laget.Db.Dapper --version 2.1.35.74
NuGet\Install-Package laget.Db.Dapper -Version 2.1.35.74
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="2.1.35.74" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add laget.Db.Dapper --version 2.1.35.74
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: laget.Db.Dapper, 2.1.35.74"
#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=2.1.35.74 // Install laget.Db.Dapper as a Cake Tool #tool nuget:?package=laget.Db.Dapper&version=2.1.35.74
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> 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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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.1.35)
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- System.ComponentModel.Annotations (>= 5.0.0)
-
.NETStandard 2.1
- Dapper (>= 2.1.35)
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net6.0
- Dapper (>= 2.1.35)
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net8.0
- Dapper (>= 2.1.35)
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- 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 | |
---|---|---|---|
2.1.35.74 | 109 | 11/4/2024 | |
1.6.72 | 149 | 9/3/2024 | |
1.6.71 | 133 | 6/3/2024 | |
1.6.70 | 152 | 4/5/2024 | |
1.6.69 | 240 | 3/4/2024 | |
1.6.68 | 228 | 2/9/2024 | |
1.6.67 | 156 | 1/20/2024 | |
1.6.65 | 121 | 1/19/2024 | |
1.6.64 | 118 | 1/19/2024 | |
1.6.63 | 170 | 1/8/2024 | |
1.6.62 | 199 | 12/6/2023 | |
1.6.61 | 155 | 11/22/2023 | |
1.6.60 | 150 | 11/10/2023 | |
1.6.59 | 139 | 11/10/2023 | |
1.5.58 | 129 | 11/10/2023 | |
1.5.57 | 145 | 11/6/2023 | |
1.5.56 | 192 | 10/2/2023 | |
1.5.55 | 174 | 9/4/2023 | |
1.5.54 | 183 | 7/3/2023 | |
1.5.53 | 178 | 6/29/2023 | |
1.4.45 | 169 | 6/13/2023 | |
1.3.42 | 166 | 5/26/2023 | |
1.3.41 | 213 | 4/4/2023 | |
1.3.40 | 214 | 4/3/2023 | |
1.2.39 | 259 | 3/10/2023 | |
1.2.38 | 247 | 3/10/2023 | |
1.1.27 | 310 | 2/6/2023 | |
1.1.23 | 332 | 12/5/2022 | |
1.1.22 | 370 | 11/7/2022 | |
1.1.19 | 456 | 8/22/2022 | |
1.1.17 | 453 | 6/7/2022 | |
1.1.16 | 512 | 3/7/2022 | |
1.1.15 | 453 | 2/7/2022 | |
1.1.14 | 320 | 12/21/2021 | |
1.1.13 | 351 | 11/28/2021 | |
1.1.12 | 355 | 11/10/2021 | |
1.1.11 | 358 | 11/10/2021 | |
1.1.9 | 559 | 10/4/2021 | |
1.1.8 | 503 | 8/23/2021 | |
1.1.7 | 435 | 8/16/2021 | |
1.1.6 | 387 | 7/7/2021 | |
1.1.5 | 402 | 7/5/2021 | |
1.1.4 | 405 | 6/28/2021 | |
1.1.2 | 429 | 6/7/2021 | |
1.1.1 | 400 | 5/21/2021 | |
1.0.18 | 446 | 5/3/2021 | |
1.0.17 | 432 | 4/6/2021 | |
1.0.16 | 413 | 3/5/2021 | |
1.0.15 | 471 | 2/11/2021 | |
1.0.14 | 424 | 2/1/2021 | |
1.0.13 | 596 | 1/8/2021 | |
1.0.12 | 434 | 1/8/2021 | |
1.0.11 | 496 | 1/1/2021 | |
1.0.10 | 508 | 12/23/2020 | |
1.0.9 | 417 | 12/22/2020 | |
1.0.8 | 482 | 12/22/2020 | |
1.0.7 | 397 | 12/22/2020 | |
1.0.6 | 486 | 12/16/2020 | |
1.0.5 | 498 | 12/9/2020 | |
1.0.4 | 433 | 12/8/2020 | |
1.0.3 | 411 | 12/8/2020 | |
1.0.2 | 407 | 12/8/2020 | |
1.0.1 | 431 | 12/8/2020 |