Net4x.DapperLibrary.Extensions.Archive
1.9.9.6
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 3.5
This package targets .NET Framework 3.5. The package is compatible with this framework or higher.
dotnet add package Net4x.DapperLibrary.Extensions.Archive --version 1.9.9.6
NuGet\Install-Package Net4x.DapperLibrary.Extensions.Archive -Version 1.9.9.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="Net4x.DapperLibrary.Extensions.Archive" Version="1.9.9.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.DapperLibrary.Extensions.Archive" Version="1.9.9.6" />
<PackageReference Include="Net4x.DapperLibrary.Extensions.Archive" />
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 Net4x.DapperLibrary.Extensions.Archive --version 1.9.9.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Net4x.DapperLibrary.Extensions.Archive, 1.9.9.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 Net4x.DapperLibrary.Extensions.Archive@1.9.9.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=Net4x.DapperLibrary.Extensions.Archive&version=1.9.9.6
#tool nuget:?package=Net4x.DapperLibrary.Extensions.Archive&version=1.9.9.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DapperLibrary.Extensions.Archive
Utilities to create archive tables and move old data to archive tables when saving DataTable/DataSet instances via IDapperContext.
Overview
- Purpose: provide a standard workflow for archiving table contents before replacing or truncating the original table. The archive helpers can create archive tables (if needed), enrich primary keys with additional columns (e.g. modified date), delete archived rows from the original table and persist archived rows to the archive table.
- Prefix-based: archive table names are produced by adding a configured prefix to the original table name.
Main types
ArchiveSetting- Configuration model that contains:
PrefixToArchiveandPrefixArchived� prefixes used to identify tables to archive and the archived target name.IsArchiveEnabled� toggle archiving behaviour.PrimaryKeysForTableType� strategy for determining primary keys for tables (IPrimaryKeysForTableTypefromDapperLibrary.Data).
- Configuration model that contains:
ITableArchiver- Interface describing archive operations that can be implemented to customize archiving behavior. Main methods:
ArchiveOldTableAsync(...)� move or save existing rows to the archive and remove them from the original table.CreateArchiveTableIfNotExists(...)� ensure the archive table exists with the appropriate schema before archiving.
- Interface describing archive operations that can be implemented to customize archiving behavior. Main methods:
TableArchiver(default implementation)- Implements
ITableArchiverand provides the default archiving logic:- Loads the source table via
IDapperContext.LoadDataTableFromNameAsync. - Creates the archive table if missing.
- Enriches primary keys (adds any
columnsToAddas part of the composite primary key) so archived rows can include e.g. modification timestamps. - Deletes the archived rows from the original table in chunks and saves archived rows to the archive table.
- Loads the source table via
- Implements
Extension methods
SaveDataTableExtension/SaveDataSetExtension- Provide
SaveDataTable/SaveDataSetand async overloads that integrate archiving into the save flow. - Default overloads use the context's
ConnectionStringToReadbut connection-specific methods are available. - Parameters commonly used:
primaryKeySize� size to use when creating primary key columns on new tables.chunkSize� number of rows to delete at once when removing archived rows from the original table.columnsToAdd� extra columns that get added to the primary key of archived rows (for exampleModifiedDate).emptyTable� whether to empty/replace the original table before saving.addDateSuffix� append a date suffix to the table name when saving (useful to avoid name collisions).rowPreProcessor� optionalIRowPreProcessorcalled before save to modify rows (e.g. generate UUIDs).tableArchiver� customITableArchiverimplementation (ifnull, defaultTableArchiverlogic is used).
- Provide
CreateTableExtension/CreateOrEmptyOriginalAndSaveTableExtension- Helpers to create or recreate the target table and then save the data while optionally archiving the old contents.
Behavior notes
- Archiving is opt-in via the
ArchiveSetting.IsArchiveEnabledflag; when disabled the archiver is a no-op. - The archiving logic guards against double-archiving by skipping tables whose names already start with the configured
PrefixToArchiveorPrefixArchived. - The default archiver sets archive table primary keys using the configured
IPrimaryKeysForTableTypeand appends any specifiedcolumnsToAddto the composite primary key. - Deletions from the original table are performed in chunks to avoid locking large operations.
Example
var archiveSetting = new ArchiveSetting("ToArchive_", "Archived_", true, new MyPrimaryKeysForTableType());
// Save a single DataTable while archiving old rows:
var (affectedRows, sql) = await dapperContext.SaveDataTableAsync(
dataTable,
rowPreProcessor: null,
primaryKeySize: 50,
emptyTable: false,
archiveSetting: archiveSetting,
tableArchiver: null, // use default TableArchiver
chunkSize: 1000,
addDateSuffix: false
);
// Or save an entire DataSet and archive each table as needed:
var (totalAffected, sqlStatements) = await dapperContext.SaveDataSetAsync(
dataSet,
connectionStringName: "MyConnection",
rowPreProcessor: null,
primaryKeySize: 50,
archiveSetting: archiveSetting,
tableArchiver: null,
emptyTable: false,
chunkSize: 1000
);
Dependencies and compatibility
- Built on top of
DapperLibrary.DbContextsandDapperLibrary.Dataabstractions. - This project contains code paths for older .NET Framework targets and modern .NET Standard/.NET runtimes; include compatible DapperLibrary assemblies for your target framework.
Extensibility
- Implement
ITableArchiverfor custom archiving strategies (e.g. copy to external storage, compress archived rows, or transmit them to a separate archival database). - Provide a custom
IPrimaryKeysForTableTypeimplementation to control how primary keys are detected or assigned for different table types.
License / Contributing
See repository root for license and contribution guidelines.
| 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. 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 | net35 is compatible. net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 is compatible. 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.
-
.NETFramework 3.5
- Net4x.AsyncBridge (>= 1.5.0.8)
- Net4x.DapperLibrary.Base (>= 1.9.9.6)
- Net4x.DapperLibrary.Extensions.Base (>= 1.9.9.6)
-
.NETFramework 4.0
- Net4x.AsyncBridge (>= 1.5.0.8)
- Net4x.DapperLibrary.Base (>= 1.9.9.6)
- Net4x.DapperLibrary.Extensions.Base (>= 1.9.9.6)
-
.NETFramework 4.5
- Net4x.AsyncBridge (>= 1.5.0.8)
- Net4x.DapperLibrary.Base (>= 1.9.9.6)
- Net4x.DapperLibrary.Extensions.Base (>= 1.9.9.6)
- System.Text.RegularExpressions (>= 4.3.1)
-
.NETFramework 4.6.1
- Net4x.AsyncBridge (>= 1.5.0.8)
- Net4x.DapperLibrary.Base (>= 1.9.9.6)
- Net4x.DapperLibrary.Extensions.Base (>= 1.9.9.6)
- System.Configuration.ConfigurationManager (>= 9.0.0)
- System.Data.Common (>= 4.3.0)
- System.Text.RegularExpressions (>= 4.3.1)
-
.NETStandard 2.0
- Net4x.AsyncBridge (>= 1.5.0.8)
- Net4x.DapperLibrary.Base (>= 1.9.9.6)
- Net4x.DapperLibrary.Extensions.Base (>= 1.9.9.6)
- System.Configuration.ConfigurationManager (>= 9.0.0)
- System.Data.Common (>= 4.3.0)
- System.Text.RegularExpressions (>= 4.3.1)
-
.NETStandard 2.1
- Net4x.AsyncBridge (>= 1.5.0.8)
- Net4x.DapperLibrary.Base (>= 1.9.9.6)
- Net4x.DapperLibrary.Extensions.Base (>= 1.9.9.6)
- System.Configuration.ConfigurationManager (>= 9.0.0)
- System.Data.Common (>= 4.3.0)
- System.Text.RegularExpressions (>= 4.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.