Net4x.DapperLibrary.Pivot
1.9.9.26248
.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.Pivot --version 1.9.9.26248
NuGet\Install-Package Net4x.DapperLibrary.Pivot -Version 1.9.9.26248
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.Pivot" Version="1.9.9.26248" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.DapperLibrary.Pivot" Version="1.9.9.26248" />
<PackageReference Include="Net4x.DapperLibrary.Pivot" />
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.Pivot --version 1.9.9.26248
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Net4x.DapperLibrary.Pivot, 1.9.9.26248"
#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.Pivot@1.9.9.26248
#: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.Pivot&version=1.9.9.26248
#tool nuget:?package=Net4x.DapperLibrary.Pivot&version=1.9.9.26248
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DapperLibrary.Pivot
Utilities to pivot a DataTable (rows ? columns) with a small, dependency-light API.
Purpose
- Provide an in-memory pivot operation on ADO.NET
DataTableinstances. - Support two modes:
- Count mode: when
columnsWithDataToPivotisnull, the pivot produces one column per distinct value encountered and a final count column. - Value mode: when
columnsWithDataToPivotis provided, specified source columns are used to form pivoted columns and values are aggregated or joined per pivot cell.
- Count mode: when
Main types
Pivot� factory withCreateInstance()returning anIPivotimplementation.IPivot� interface exposingPivot(DataTable? sourceDatatable, Dictionary<string,string[]>? columnsWithDataToPivot, params string[] columnsAsPivotPrimaryKey).PivotInternal� internal implementation that performs the pivot logic. It usesArgumentGetter.Instanceto obtain the defaultCountColumnNameand logs exceptions viaCoreLibrary.Logging.- Extensions: helper methods under
Extensions(DataTableHelper,PivotExtensions) assist with table operations and lookups.
API
IPivot.Pivot(DataTable? sourceDatatable, Dictionary<string,string[]>? columnsWithDataToPivot, params string[] columnsAsPivotPrimaryKey)sourceDatatable: source rows to pivot. Ifnull, an initial pivot table structure is still returned where possible.columnsWithDataToPivot: whennull, the method runs in "count" mode and adds a count column; otherwise it maps source columns to lists of column names whose values become pivoted columns.- The dictionary keys are source column names. The dictionary values are arrays of column names whose values should be used when building the pivot cell value for that key.
- A special dictionary key of "*" may be used to indicate wildcard columns to include additional values for composed cells.
columnsAsPivotPrimaryKey: one or more source column names that become the primary key columns of the resulting pivot table. Rows are grouped by these columns when building the pivot.
Behavior notes
- The pivot result uses the provided
columnsAsPivotPrimaryKeyas the pivot table primary key. New rows are created when a primary key combination is not present. - Column names for pivoted values are taken from the string representation of source cell values. In count mode a numeric count column (default name from configuration, e.g. "Count") is appended.
- When
columnsWithDataToPivotis provided, pivot cell values are either an aggregated count or a joined string of values (joined with " - ") depending on whether mapping lists are empty. - The implementation logs exceptions and returns
nullon error. - Default
CountColumnNamecan be configured viaConfigurationLibrary.Arguments(argument name "CountColumnName").
Example
using System.Data;
using DapperLibrary;
var pivot = Pivot.CreateInstance();
// Source table must contain the columns used as primary key and the columns to pivot
var source = new DataTable();
source.Columns.Add("Category", typeof(string));
source.Columns.Add("Type", typeof(string));
source.Columns.Add("Value", typeof(string));
source.Rows.Add("A", "X", "10");
source.Rows.Add("A", "Y", "20");
source.Rows.Add("B", "X", "5");
// columnsWithDataToPivot maps the source column to which columns provide values for the pivot
var columnsWithDataToPivot = new Dictionary<string,string[]>
{
{ "Type", new[] { "Value" } }
};
// Use "Category" as the pivot primary key
var result = pivot.Pivot(source, columnsWithDataToPivot, "Category");
// result will have one row per Category and a column for each distinct Type value (e.g. "X", "Y").
// Each pivot cell contains the joined Value(s) for that Category/Type.
Dependencies
- The pivot implementation relies on
CoreLibrary.Utility.Conversionfor conversions andCoreLibrary.Loggingfor error reporting. ConfigurationLibrary.Argumentsis used to read the defaultCountColumnNamesetting.
Threading and performance
- The pivot operation is in-memory and works on
DataTableinstances; it is not optimized for very large datasets. For large data volumes consider streaming/aggregation approaches. - The implementation is not explicitly thread-safe for concurrent mutations of the same
DataTableinstance.
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.26243)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Base (>= 2.5.0.26236)
- Net4x.CoreLibrary.Logging (>= 2.5.0.26236)
-
.NETFramework 4.0
- Net4x.AsyncBridge (>= 1.5.0.26243)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Base (>= 2.5.0.26236)
- Net4x.CoreLibrary.Logging (>= 2.5.0.26236)
-
.NETFramework 4.5
- Net4x.AsyncBridge (>= 1.5.0.26243)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Base (>= 2.5.0.26236)
- Net4x.CoreLibrary.Logging (>= 2.5.0.26236)
-
.NETFramework 4.6.1
- Net4x.AsyncBridge (>= 1.5.0.26243)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Base (>= 2.5.0.26236)
- Net4x.CoreLibrary.Logging (>= 2.5.0.26236)
-
.NETStandard 2.0
- Net4x.AsyncBridge (>= 1.5.0.26243)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Base (>= 2.5.0.26236)
- Net4x.CoreLibrary.Logging (>= 2.5.0.26236)
-
.NETStandard 2.1
- Net4x.AsyncBridge (>= 1.5.0.26243)
- Net4x.Configuration.Library (>= 2.5.0.26236)
- Net4x.CoreLibrary.Base (>= 2.5.0.26236)
- Net4x.CoreLibrary.Logging (>= 2.5.0.26236)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.