Linger.DataAccess 0.9.5

dotnet add package Linger.DataAccess --version 0.9.5
                    
NuGet\Install-Package Linger.DataAccess -Version 0.9.5
                    
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="Linger.DataAccess" Version="0.9.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.DataAccess" Version="0.9.5" />
                    
Directory.Packages.props
<PackageReference Include="Linger.DataAccess" />
                    
Project file
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 Linger.DataAccess --version 0.9.5
                    
#r "nuget: Linger.DataAccess, 0.9.5"
                    
#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 Linger.DataAccess@0.9.5
                    
#: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=Linger.DataAccess&version=0.9.5
                    
Install as a Cake Addin
#tool nuget:?package=Linger.DataAccess&version=0.9.5
                    
Install as a Cake Tool

Linger.DataAccess

中文 | English

Core data access library providing database abstraction and common database operations.

Features

  • Database Abstraction: Provider-agnostic database access
  • CRUD Operations: Complete Create, Read, Update, Delete operations
  • Async Support: Full async/await support for modern applications
  • Multiple Data Types: Support for DataTable, DataSet, Entity objects, and Hashtable
  • Transaction Support: Built-in transaction management
  • SQL Builder: Helper for dynamic SQL generation
  • Bulk Operations: Interface for high-performance bulk data insertion
  • Batch Query: Large parameter list splitting (default batchSize = 1000) with parameterized & raw variants

Supported .NET Versions

  • .NET 9.0
  • .NET 8.0
  • .NET Framework 4.6.2+

Installation

This library is typically not installed directly, but is automatically referenced when installing specific database implementation packages:

# For SQL Server
dotnet add package Linger.DataAccess.SqlServer

# For Oracle Database
dotnet add package Linger.DataAccess.Oracle

# For SQLite
dotnet add package Linger.DataAccess.Sqlite

Core Interfaces

IDatabase

The main interface providing comprehensive database operations:

// Execute operations
int ExecuteBySql(string sql);
int ExecuteByProc(string procName, DbParameter[] parameters);

// Query operations
List<T> FindListBySql<T>(string sql);
DataTable FindTableBySql(string sql, DbParameter[] parameters);
DataSet FindDataSetBySql(string sql, DbParameter[] parameters);

// Batch query operations
DataTable QueryInBatches(string sql, List<string> parameters, int batchSize = 1000);
Task<DataTable> QueryInBatchesAsync(string sql, List<string> parameters, int batchSize = 1000, CancellationToken cancellationToken = default);
DataTable QueryInBatchesRaw(string sql, List<string> values, int batchSize = 1000, bool quote = true);
Task<DataTable> QueryInBatchesRawAsync(string sql, List<string> values, int batchSize = 1000, bool quote = true, CancellationToken cancellationToken = default);

// Async operations
Task<DataTable> FindTableBySqlAsync(string sql);
Task<DataSet> FindDataSetBySqlAsync(string sql, DbParameter[] parameters);
Task<int> FindCountBySqlAsync(string sql);

// Entity operations
T FindEntityBySql<T>(string sql, DbParameter[] parameters);
Hashtable FindHashtableBySql(string sql, DbParameter[] parameters);

// Bulk operations
bool BulkInsert(DataTable dt);

IProvider

Database provider abstraction for different database engines.

Basic Usage

using Linger.DataAccess;

// Execute queries
var users = database.FindListBySql<User>("SELECT * FROM Users WHERE Active = 1");
var userTable = await database.FindTableBySqlAsync("SELECT * FROM Users");

// Batch query (IDs split automatically, default batchSize 1000)
var ids = Enumerable.Range(1, 5000).Select(i => i.ToString()).ToList();
var dt = database.QueryInBatches("SELECT * FROM Users WHERE Id IN ({0})", ids);

// Custom batch size
var dt500 = database.QueryInBatches("SELECT * FROM Users WHERE Id IN ({0})", ids, 500);

// Raw version (trusted numeric IDs only)
var dtRaw = database.QueryInBatchesRaw("SELECT * FROM Users WHERE Id IN ({0})", ids, 800, quote: false);

// Async parameterized version
var dtAsync = await database.QueryInBatchesAsync("SELECT * FROM Users WHERE Id IN ({0})", ids, 750);

// Execute commands
int affected = database.ExecuteBySql("UPDATE Users SET LastLogin = GETDATE()");

// Count operations
int userCount = await database.FindCountBySqlAsync("SELECT COUNT(*) FROM Users");

Batch Query

When dealing with very large IN lists (thousands of IDs) a single SQL statement may exceed length limits or degrade performance. The batch query helpers automatically split the list and concatenate the results.

// Parameterized (safe)
var result = database.QueryInBatches(
    "SELECT * FROM Orders WHERE OrderId IN ({0})",
    orderIds); // default batchSize = 1000

// Raw (only for trusted constant values)
var resultRaw = database.QueryInBatchesRaw(
    "SELECT * FROM Orders WHERE OrderId IN ({0})",
    orderIds, 500, quote: false);

Guidelines:

  • Use {0} in sql where the batch placeholder will be injected.
  • Prefer parameterized methods for security (prevents SQL injection).
  • Raw methods are only for fully trusted data (e.g., internally generated numeric IDs).
  • Adjust batchSize to balance network round-trips and SQL size limits.

Return Type:

  • All batch methods merge rows into a single DataTable preserving schema of the first non-empty batch.

Architecture

This library provides the foundation for database-specific implementations:

  • Linger.DataAccess.SqlServer - SQL Server implementation
  • Linger.DataAccess.Oracle - Oracle Database implementation
  • Linger.DataAccess.Sqlite - SQLite implementation

Key Components

Database Class

Base implementation of IDatabase interface providing common database operations.

BaseDatabase Class

Core database functionality including connection management and parameter handling.

SqlBuilder Class

Helper utility for building dynamic SQL queries safely.

Best Practices

  • Use parameterized queries to prevent SQL injection
  • Use batch query helpers for large IN lists instead of manual concatenation
  • Implement proper disposal patterns with using statements
  • Use async methods for I/O intensive operations
  • Choose appropriate database-specific implementations for optimal performance

Contributing

This library is part of the Linger framework. Please refer to the main repository for contributing guidelines.

Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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 is compatible.  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 Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Linger.DataAccess:

Package Downloads
Linger.DataAccess.SqlServer

Package Description

Linger.DataAccess.Sqlite

Package Description

Linger.DataAccess.Oracle

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.5 29 9/28/2025
0.9.4-preview 109 9/25/2025
0.9.3-preview 131 9/22/2025
0.9.2-preview 147 9/21/2025
0.9.1-preview 251 9/16/2025
0.9.0-preview 72 9/12/2025
0.8.5-preview 145 8/31/2025
0.8.4-preview 258 8/25/2025
0.8.3-preview 121 8/20/2025
0.8.2-preview 151 8/4/2025
0.8.1-preview 96 7/30/2025
0.1.2-alpha 88 12/17/2024
0.1.1-alpha 73 12/17/2024
0.1.0-alpha 74 12/6/2024
0.0.3-alpha 71 12/6/2024
0.0.2-alpha 73 10/3/2024