RepositoryPatternEfCoreSimple 0.0.6
.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 RepositoryPatternEfCoreSimple --version 0.0.6
NuGet\Install-Package RepositoryPatternEfCoreSimple -Version 0.0.6
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="RepositoryPatternEfCoreSimple" Version="0.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RepositoryPatternEfCoreSimple" Version="0.0.6" />
<PackageReference Include="RepositoryPatternEfCoreSimple" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RepositoryPatternEfCoreSimple --version 0.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RepositoryPatternEfCoreSimple, 0.0.6"
#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.
#:package RepositoryPatternEfCoreSimple@0.0.6
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RepositoryPatternEfCoreSimple&version=0.0.6
#tool nuget:?package=RepositoryPatternEfCoreSimple&version=0.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Repository pattern
Repository pattern implementation focused on EF Core.
Getting started
Add package to the project
dotnet add package RepositoryPatternEfCoreSimple
Create a repository
public class MyEntityRepository : RepositoryEfCore<MyEntity, MyDbContext>
{
public MyEntityRepository(MyDbContext context) : base(context)
{
}
public MyEntityRepository(MyDbContext context, ILogger<MyEntityRepository> logger) : base(context, logger)
{
}
}
Use the repository
var repository = new MyEntityRepository(context); // or use DI
// Add syncronously new entity
repository.Add(new MyEntity()); // This will add the entity to the context and saves the changes
// Add asyncronously new entity
await repository.AddAsync(new MyEntity()).ConfigureAwait(false) ; // This will add the entity to the context and saves the changes asyncronously
Getting started when is needded regularly delete old data
Add package to the project
dotnet add package RepositoryPatternEfCoreSimple
Create a repository
public class MyEntityRepository : RepositoryEfCoreCleanable<MyEntity, MyDbContext>
{
public MyEntityRepository(MyDbContext context) : base(context)
{
}
public MyEntityRepository(MyDbContext context, ILogger<MyEntityRepository> logger) : base(context, logger)
{
}
/// <summary>
/// Deletes single data batch (of size <paramref name="take"/>).
/// Example for Oracle
/// </summary>
/// <param name="retentionPeriod">How old data are kept. Older data are deleted</param>
/// <param name="take"></param>
/// <returns>Number of deleted items. Should be between zero and <paramref name="take"/></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public async override Task<int> RemoveOneBatchAsync(TimeSpan retentionPeriod, int take)
{
logger.LogTrace($"RemoveOneBatchAsync started for retentionPeriod {retentionPeriod} and take {take}");
if (take < 1) throw new ArgumentOutOfRangeException(nameof(take));
var deletedRows = 0;
var olderThan = DateTime.Now - retentionPeriod;
//string command = "DELETE FROM MY_TABLE WHERE timestamp < :date"; // replace MY_TABLE by your table name
deletedRows = context.Database.ExecuteSqlRaw("DELETE FROM MY_TABLE where ROWNUM <= {0} and timestamp < {1}", take, olderThan);
logger.LogTrace($"RemoveOneBatchAsync finished deleted {deletedRows} for retentionPeriod {retentionPeriod} and take {take}");
return deletedRows;
}
}
Use the repository
var repository = new MyEntityRepository(context); // or use DI
// Delete old data
TimeSpan dataRetentionPeriod = TimeSpan a = TimeSpan.FromDays(30); // Delete data older than 30 days
int batchSize => 1000; // Delete data in batches . No more tha 1000 rows are deleted in one DB transaction
repository.RemoveOldAsync(dataRetentionPeriod, batchSize).ConfigureAwait(false);
Versions
0.0.6
- Added EfCoreCleanable<TDbContext>` to enable priodical cleaning only using context (without the need to define Entity)
0.0.5
Improved logging to support parameters
0.0.4
Added documetation
0.0.3
Initial version with RepositoryEfCoreCleanable
implementation
0.0.0-alpha4
Added Count(expresion)
and CountAsync(expresion)
0.0.0-alpha3
Removed TId and Indetifyiable interface. Now the repository is generic and the key is defined by the entity.
0.0.0-alpha2
Initial version with RepositoryEfCore
implementation
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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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
- Microsoft.EntityFrameworkCore (>= 3.1.32)
- Microsoft.EntityFrameworkCore.Abstractions (>= 3.1.32)
-
.NETStandard 2.1
- Microsoft.EntityFrameworkCore (>= 5.0.17)
- Microsoft.EntityFrameworkCore.Abstractions (>= 5.0.17)
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.29)
- Microsoft.EntityFrameworkCore.Abstractions (>= 6.0.29)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.EntityFrameworkCore.Abstractions (>= 8.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 |
---|---|---|
0.0.6 | 139 | 10/1/2024 |
0.0.4 | 142 | 6/21/2024 |
0.0.3 | 127 | 6/21/2024 |
0.0.0.5 | 114 | 9/18/2024 |
0.0.0-alpha2 | 110 | 4/26/2024 |