![]() |
VOOZH | about |
dotnet add package Net4x.DapperLibrary.Base --version 1.9.9.8
NuGet\Install-Package Net4x.DapperLibrary.Base -Version 1.9.9.8
<PackageReference Include="Net4x.DapperLibrary.Base" Version="1.9.9.8" />
<PackageVersion Include="Net4x.DapperLibrary.Base" Version="1.9.9.8" />Directory.Packages.props
<PackageReference Include="Net4x.DapperLibrary.Base" />Project file
paket add Net4x.DapperLibrary.Base --version 1.9.9.8
#r "nuget: Net4x.DapperLibrary.Base, 1.9.9.8"
#:package Net4x.DapperLibrary.Base@1.9.9.8
#addin nuget:?package=Net4x.DapperLibrary.Base&version=1.9.9.8Install as a Cake Addin
#tool nuget:?package=Net4x.DapperLibrary.Base&version=1.9.9.8Install as a Cake Tool
DapperLibrary is a lightweight data-access library that builds on ADO.NET and Dapper to provide a consistent, engine-agnostic API for querying and manipulating relational databases. The library centers on the DapperContext class and the IDapperContext interface which encapsulate connection creation, command execution, parameter handling and schema helpers.
DapperContext (concrete) and IDapperContext (interface). Create an instance of DapperContext (or use a provider-specific derived context) and use it via the IDapperContext surface to execute commands and queries.DapperContext manages connection lifetime automatically and exposes a rich set of synchronous and asynchronous operations.This repository is designed to support a broad range of .NET frameworks to make the library usable in legacy and modern applications. The source contains conditional compilation directives and multi-targeted build configurations so different assemblies are produced for different target frameworks. Supported frameworks include (but are not limited to):
Notes about multi-targeting:
ConfigurationManager, IHostApplicationBuilder availability, or System.Text.Json vs Newtonsoft.Json), the library exposes equivalent surface behavior while using the most appropriate underlying runtime facility.IDapperContext / DapperContext
DapperContext instance to obtain database access. The instance is responsible for creating and tracking DbConnection instances and for closing them when appropriate.IDapperContext exposes an Operations/Schema surface for segregated responsibilities (query/set operations vs schema inspection).SqlDapperContext, MySqlDapperContext) to simplify engine-specific configuration and lifetime semantics.Multiple connection types and mixing engines
DapperContext objects for different engines and mix them in the same application.SqlDapperContext.Use(), SqlDapperContext.UseOnce(), MySqlDapperContext.Use(), MySqlDapperContext.UseOnce() to simplify scoped or one-off usage.In-memory & mocked database support
DapperContext provides several APIs and properties to control which connection string is used for operations and how a connection string is resolved:
ConnectionStringToRead (string)
context.ConnectionStringToRead = "MyOtherConnection".ConnectionStringSettings and AlternativeConnectionString
ConnectionStringSettings can hold the currently active connection settings. When a configured ConnectionStringSettings is present the context will prefer its connection string.AlternativeConnectionString serves as a fallback value if no configuration provider or settings supply a concrete connection string.ConnectionStrings (IConnectionStrings)
ConnectionStrings collection that is initialized from the owning DapperContextFactory / configuration manager. Use context.ConnectionStrings[...] or the ConnectionStrings.Current helpers to inspect available named connections.GetConnectionString(string connectionStringName)
AlternativeConnectionString, and raises a ConnectionStringEventArgs that can be patched by DapperContextFactory internals.Custom connections via indexer
context[connectionStringName] returns an ICustomConnection bound to that name (useful for per-connection shortcuts and schema helpers).Notes and best practices
ConnectionStringToRead once during initialization when a context is used for a single logical database. Change it dynamically only when you understand the effect on pooled/allocated connections.WithConnection(...) overload when you must perform an operation against a different database for a single call; that avoids race conditions around concurrent operations and reader-associated connections.DapperContext per engine/connection string to keep behavior predictable and to avoid mixing provider factories.DapperLibrary exposes a typed, convenient schema inspection surface through IDapperContext.Schema (and the concrete DapperContext.Schema property). The ISchema surface aggregates small helper types that make reading table metadata easy and concise.
ISchema (examples):
ColumnNames � indexer ColumnNames[tableName] returns an array of column names for the table.IdentityColumnIndex � indexer IdentityColumnIndex[tableName] returns the ordinal of the identity/autoincrement column.IdentityColumn � indexer IdentityColumn[tableName] returns the identity column name (if any).PrimaryKeyColumnNames � indexer PrimaryKeyColumnNames[tableName] returns the primary key column names.SchemaTableTypes � indexer SchemaTableTypes[tableName] returns an array of rich SchemaTable descriptors.UniqueKeyColumnNames � indexer UniqueKeyColumnNames[tableName] returns unique columns.AllowDbNull, ColumnOrdinal, ColumnSize, ColumnType, NumericPrecision, NumericScale, ProviderType � each type exposes indexers with either a (tableName, columnName) or (tableName, index) overload for convenience.Usage examples:
var names = context.Schema.ColumnNames["Orders"];var dt = context.Schema.ColumnType["Orders", "OrderDate"];var idx = context.Schema.IdentityColumnIndex["Orders"];With-connection overloads
connectionStringName. When a helper is initialized with a connection string the indexers call *WithConnection variants internally (for example GetSchemaTableWithConnection) so you can query schema on a different named connection via context.SchemaWithConnection(name)-style factories (the library exposes ways to build schema helpers bound to a named connection).Caching behavior
GetSchemaTableWithConnection(...), which uses CacheUtility.Instance.GetValueFromCache with a cache key typically built from the resolved connection string and the table name. Common cache keys follow the pattern: ${connectionString}_${tableName}_SchemaTable, ${connectionString}_${tableName}_ColumnNames, etc.SchemaTable[], column names arrays and other derived values. The cache reduces round-trips and speeds up repeated metadata inspection.Cache invalidation
CleanCacheForTable and the internal paths that call it).DapperContext (e.g., manually via another process), you may need to evict or refresh the cache programmatically. The internal CacheUtility API is used for caching; extend or call into that helper to control cache lifetime if required.Best practices
DapperContext operations so the library can invalidate cached metadata.DapperContext opens DbConnection instances as needed and keeps track of them in an internal Behavior container.
If a DbDataReader is opened on a connection, and you execute another statement on the same DapperContext, a new connection will be opened automatically to avoid interfering with the reader.
Disposing the DapperContext will close all owned connections. If a DapperContext is not explicitly disposed, its finalizer will still attempt to close open connections when the GC collects the object.
You can explicitly close the connection associated with a specific reader using DapperContext.CloseConnectionAssociatedWithDataReader(DbDataReader reader).
The property DapperContext.CloseConnection controls detailed closing behavior; it maps to underlying CommandBehavior and Behavior.KeepOpen semantics. The library supports the three typical behaviours:
AsSoonAsPossible � connections closed immediately after operations completeWhenDataReaderCloses � keep connection open until the reader is disposedAtDispose � keep connections open until the DapperContext is disposedInspect the Behavior and CloseConnection usage in DapperContext and related code to see how the container selects, reuses, and disposes connections.
{i} or {i:out} inside a statement.
SELECT {0:out}, Field1, {1}+' Test' FROM SqlTestTable WHERE KeyField = {2}SELECT @Par0, Field1, @Par1+' Test' FROM SqlTestTable WHERE KeyField = @Par2 (parameter names like @Par0, @Par1, etc.).ParameterModel class and related helpers such as ParameterModel.DefaultPrepareCommandParameters (see ParameterModel.PrepareDynamicParameters and PrepareCommandParameters for details).
:out marker), named parameters, and dynamic parameter objects (Dapper DynamicParameters).DapperLibrary exposes both synchronous and asynchronous versions of most operations so it can be used in synchronous legacy applications as well as modern async/await code paths. Common patterns and guidance:
Async suffix variant. Examples:
GetDataTable, GetDataReader, SetData, GetScalar<T>, SaveDataTable, Save<T> etc.GetDataTableAsync, GetDataReaderAsync, SetDataAsync, GetScalarAsync<T>, SaveDataTableAsync, SaveAsync<T> etc.DbCommand / DbDataReader async methods where supported by the provider and are guarded by conditional compilation for older frameworks that do not support Task-based ADO.NET async APIs.DapperContext, be mindful of connection reentrancy: opening a long-lived DbDataReader via a sync call may cause subsequent operations to open separate connections; prefer async patterns end-to-end when using async readers.Basic ADO.NET style operations
GetScalar<T> � executes a command and returns a scalar value (ExecuteScalar behavior)GetDataReader � open a reader (ExecuteReader behavior)SetData � execute non-query statements (ExecuteNonQuery behavior)GetDataTable / GetDataSet � build a DataTable/DataSet from reader resultsSaveDataTable � use a DbDataAdapter to persist a DataTable to the database (adapter commands created from table schema)Dapper-based query operations
Query<T> � maps rows to entities via Dapper Query<T>QuerySingle<T>, QueryFirstOrDefault<T> � single-row mappingQueryMultiple � use Dapper QueryMultiple to read multiple result setsEntity-oriented persistence helpers
Save<T> and SaveEnumerable<T> to persist entities (single and enumerable)Delete<T> and DeleteEnumerable<T> to remove entitiesSchema helpers
Schema helpers expose metadata like column names, column sizes, types, primary keys and identity column info.IDapperContext.Schema to inspect table metadata in a provider-agnostic manner.To customize entity-to-table mapping the library supports attributes on entity classes and properties. Typical attributes include:
TableNameAttribute � map a CLR type to a specific database tableColumnNameAttribute � map a CLR property to a specific column namePrimaryKeyAttribute(int position) � define primary key properties and their orderTimestampAttribute � mark a property as a timestamp/rowversionThese attributes are used by the library�s DatabaseModel and ParameterModel to generate correct SQL and mapping behavior.
DapperLibrary ships helpers for in-memory testing (SQLite), mocked SQL Server runtimes and integration with containerized test DBs (TestContainers).* packages.NorthwindHelper).DapperContext, IDapperContext, IDapperOperations and ParameterModel.IDapperContext.Schema and implementations under DbContexts\Schema.Operations implementations and DapperContext.Operations.cs for the facade delegations.LowLevelDapperContext for direct ADO.Net interactions and DapperContextQueryUsingParameters for Dapper parameter handling.DapperLibrary provides an engine-agnostic, Dapper-enhanced data access surface centered on DapperContext/IDapperContext. It simplifies parameter handling, connection lifetime management and schema inspection while exposing common ADO.NET and Dapper operations. Ideal for apps that need a thin abstraction over multiple relational databases with strong testability support (in-memory and mocks).
This README is a placeholder. Refer to the project sources and XML documentation inside the code for detailed API usage and advanced configuration examples.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net35 net35 is compatible. net40 net40 is compatible. net403 net403 was computed. net45 net45 is compatible. net451 net451 was computed. net452 net452 was computed. net46 net46 was computed. net461 net461 is compatible. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Net4x.DapperLibrary.Base:
| Package | Downloads |
|---|---|
|
Net4x.DapperLibrary.SqlServer
Package Description |
|
|
Net4x.SpreadsheetLibrary.Base
Package Description |
|
|
Net4x.DapperLibrary.MockSqlServer
Package Description |
|
|
Net4x.DapperLibrary.SQLite
Package Description |
|
|
Net4x.DapperLibrary.StatementBuilder
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.9.9.8 | 1,002 | 2/2/2026 |
| 1.9.9.7 | 1,099 | 1/13/2026 |
| 1.9.9.6 | 1,004 | 1/6/2026 |
| 1.9.9.5 | 1,000 | 1/6/2026 |
| 1.9.9.4 | 1,000 | 1/6/2026 |
| 1.9.9.3 | 1,072 | 1/5/2026 |
| 1.9.9.2 | 977 | 12/30/2025 |
| 1.9.9.1 | 1,011 | 12/30/2025 |
| 1.9.9 | 1,089 | 12/22/2025 |
| 1.6.0.12 | 980 | 12/12/2025 |
| 1.6.0.11 | 978 | 12/12/2025 |
| 1.6.0.10 | 1,213 | 12/9/2025 |
| 1.6.0.9 | 924 | 12/4/2025 |
| 1.6.0.8 | 905 | 12/4/2025 |
| 1.6.0.7 | 984 | 11/30/2025 |
| 1.6.0.6 | 985 | 11/27/2025 |
| 1.6.0.5 | 949 | 11/22/2025 |
| 1.6.0.4 | 874 | 11/16/2025 |
| 1.6.0.3 | 848 | 11/15/2025 |
| 1.6.0.2 | 1,029 | 11/14/2025 |