Kothf.Data 2.10.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Kothf.Data --version 2.10.1
                    
NuGet\Install-Package Kothf.Data -Version 2.10.1
                    
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="Kothf.Data" Version="2.10.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kothf.Data" Version="2.10.1" />
                    
Directory.Packages.props
<PackageReference Include="Kothf.Data" />
                    
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 Kothf.Data --version 2.10.1
                    
#r "nuget: Kothf.Data, 2.10.1"
                    
#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 Kothf.Data@2.10.1
                    
#: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=Kothf.Data&version=2.10.1
                    
Install as a Cake Addin
#tool nuget:?package=Kothf.Data&version=2.10.1
                    
Install as a Cake Tool

Kothf.Data

Kothf.Data is a small ADO.NET helper library that provides a lightweight Database abstraction, an IDatabase interface, and a SqlHelper utility for creating connections, commands, and parameters.

Usage

Usage of Database

public async Task ExecuteTransactionAsync(CancellationToken stoppingToken)
{
    _logger.LogInformation("Starts to test `ExecuteTransactionAsync`");

    try
    {
        DbParameter[] parameters1 = [
            _database.CreateParameter("@p11", DbType.String, "usr001")
        ];
        string sql1 = "DELETE FROM [User] WHERE UserCode = @p11;";

        DbParameter[] parameters2 = [
            _database.CreateParameter("@p21", DbType.String, "usr001"),
            _database.CreateParameter("@p22", DbType.String, "Tom"),
            _database.CreateParameter("@p23", DbType.String, "W3Rb3AoWjXs="),
            _database.CreateParameter("@p24", DbType.String, "tom@gmail.com"),
            _database.CreateParameter("@p25", DbType.String, "18618618666")
        ];
        string sql2 = $$"""
        INSERT INTO [User] (UserCode,UserName,Password,Email,Phone,Attributes,[State],CreatedTime,LastModifiedTime) VALUES
            (@p21,@p22,@p23,@p24,@p25,1,1,GETDATE(),GETDATE());
        """;

        try
        {
            int affectedRows;
            await _database.BeginTransactionAsync(cancellationToken: stoppingToken);
            _logger.LogInformation("Starts to execute sql1");
            affectedRows = await _database.ExecuteNonQueryAsync(CommandType.Text, sql1, parameters1, stoppingToken);
            _logger.LogInformation("Removing User successfully. User code: {userCode}, affected records: {count}", "usr001", affectedRows);

            _logger.LogInformation("Starts to execute sql2");
            affectedRows = await _database.ExecuteNonQueryAsync(CommandType.Text, sql2, parameters2, stoppingToken);
            _logger.LogInformation("Adding User successfully. User code: {userCode}, affected records: {count}", "usr001", affectedRows);

            await _database.CommitAsync(stoppingToken);
        }
        catch (Exception)
        {
            await _database.RollbackAsync(stoppingToken);
            throw;
        }
    }
    catch (Exception ex)
    {
        _logger.LogError("Unhandled exception occurred during testing:\n{exception}", ex.ToString());
    }

    _logger.LogInformation("Finished Testing `ExecuteTransactionAsync`");
}

Usage of SqlHelper

public async Task ExecuteTransactionAsync(CancellationToken stoppingToken)
{
    _logger.LogInformation("Starts to test `ExecuteTransactionAsync`");

    try
    {
        DbParameter[] parameters1 = [
            SqlHelper.CreateParameter(ProviderInvariantName, "@p11", DbType.String, "usr001")
        ];
        string sql1 = "DELETE FROM [User] WHERE UserCode = @p11;";

        DbParameter[] parameters2 = [
            SqlHelper.CreateParameter(ProviderInvariantName, "@p21", DbType.String, "usr001"),
            SqlHelper.CreateParameter(ProviderInvariantName, "@p22", DbType.String, "Tom"),
            SqlHelper.CreateParameter(ProviderInvariantName, "@p23", DbType.String, "W3Rb3AoWjXs="),
            SqlHelper.CreateParameter(ProviderInvariantName, "@p24", DbType.String, "tom@gmail.com"),
            SqlHelper.CreateParameter(ProviderInvariantName, "@p25", DbType.String, "18618618666")
        ];
        string sql2 = $$"""
        INSERT INTO [User] (UserCode,UserName,Password,Email,Phone,Attributes,[State],CreatedTime,LastModifiedTime) VALUES
            (@p21,@p22,@p23,@p24,@p25,1,1,GETDATE(),GETDATE());
        """;

        using var connection = await SqlHelper.CreateConnectionAndOpenAsync(ConnectionString, ProviderInvariantName, stoppingToken);
        using var transaction = await connection.BeginTransactionAsync(stoppingToken);
        int affectedRows = 0;

        try
        {
            _logger.LogInformation("Start to execute sql1");
            using var command = SqlHelper.CreateCommand(null, transaction, CommandType.Text, sql1, parameters1);
            affectedRows = await SqlHelper.ExecuteNonQueryAsync(command, stoppingToken);
            _logger.LogInformation("Removing User successfully. User code: {userCode}, affected records: {count}", "usr001", affectedRows);

            _logger.LogInformation("Start to execute sql2");
            _ = SqlHelper.ReuseCommand(command, CommandType.Text, sql2, parameters2);
            affectedRows = await SqlHelper.ExecuteNonQueryAsync(command, stoppingToken);
            _logger.LogInformation("Adding User successfully. User code: {userCode}, affected records: {count}", "usr001", affectedRows);

            await transaction.CommitAsync(stoppingToken);
        }
        catch (Exception)
        {
            await transaction.RollbackAsync(stoppingToken);
            throw;
        }
    }
    catch (Exception ex)
    {
        _logger.LogError("Unhandled exception occurred during testing:\n{exception}", ex.ToString());
    }

    _logger.LogInformation("Finished Testing `ExecuteTransactionAsync`");
}
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 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

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
2.10.2 98 2/8/2026
2.10.1 98 1/24/2026
2.10.0 97 1/24/2026