FonsecaFramework.Sql 2026.5.21.1

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

FonsecaFramework.Sql

SQL Server and PostgreSQL database utilities for .NET.

Overview

FonsecaFramework.Sql is a .NET 9 library that simplifies database operations for both Microsoft SQL Server and PostgreSQL. It provides SqlExecuter classes for each provider, extension methods on DbConnection and DbCommand, a repository pattern implementation backed by stored procedures, and a SqlJsonObject helper for JSON-based data access.

Installation

dotnet add package FonsecaFramework.Sql

Features

Area Key Classes
Generic SQL Execution SqlExecuter (base) — provider-agnostic command execution via DbConnection
SQL Server Microsoft.SqlExecuter — SQL Server-specific executer with connection string builder
PostgreSQL Postgres.SqlExecuter — PostgreSQL-specific executer using Npgsql
DbConnection Extensions ExecuteNonQueryAsync(), ExecuteSqlToJson<T>(), ExecuteSqlToJsonAsync<T>()
DbCommand Extensions ExecuteSqlToJson<T>(), ExecuteSql() (returns DataTable), ExecuteScalar()
Repository SqlRepository<T> — stored-procedure-based CRUD repository
JSON Mapping SqlJsonObject — converts SQL JSON output to strongly-typed entities

Examples

Execute a Query with SQL Server

using FonsecaFramework.Sql.Microsoft;

var executer = new SqlExecuter("Server=myserver;Database=mydb;Trusted_Connection=True;");

// Or with explicit credentials
var executer2 = new SqlExecuter("myserver", "mydb", "user", "password");

Execute a Query with PostgreSQL

using FonsecaFramework.Sql.Postgres;

var executer = new SqlExecuter("Host=localhost;Database=mydb;Username=user;Password=pass;");

Using the Generic SqlExecuter

using FonsecaFramework.Sql;
using Microsoft.Data.SqlClient;

var executer = new SqlExecuter(() => new SqlConnection("Server=myserver;Database=mydb;Trusted_Connection=True;"));

var command = new SqlCommand("INSERT INTO Products (Name, Price) VALUES (@Name, @Price)");
command.Parameters.AddWithValue("@Name", "Widget");
command.Parameters.AddWithValue("@Price", 19.99);

await executer.ExecuteNonQueryAsync(command);

DbCommand Extensions — Query to JSON

using FonsecaFramework.Sql;
using Microsoft.Data.SqlClient;

using var connection = new SqlConnection("Server=myserver;Database=mydb;Trusted_Connection=True;");
var command = new SqlCommand("SELECT * FROM Products FOR JSON PATH");

List<Product> products = await command.ExecuteSqlToJsonAsync<List<Product>>(connection);

DbCommand Extensions — Query to DataTable

using FonsecaFramework.Sql;
using Microsoft.Data.SqlClient;

using var connection = new SqlConnection("Server=myserver;Database=mydb;Trusted_Connection=True;");
var command = new SqlCommand("SELECT * FROM Products");

DataTable table = await command.ExecuteSqlAsync(connection);
foreach (DataRow row in table.Rows)
    Console.WriteLine(row["Name"]);

SqlJsonObject — Map JSON Rows to Entities

using FonsecaFramework.Sql.Infastructure;

// When your SQL returns JSON + ID columns:
var jsonObjects = new List<SqlJsonObject>
{
    new SqlJsonObject { ID = 1, Json = "{\"Name\":\"Widget\"}" }
};

List<Product> products = SqlJsonObject.ToList<Product>(jsonObjects);

Requirements

  • .NET 9.0
  • Microsoft SQL Server and/or PostgreSQL

License

Copyright 2025 Steven Fonseca / VLR Creations

Licensed under the Apache License, Version 2.0. You may use this library free of charge, provided you include the required attribution notices. See the LICENSE file for full terms.

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

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FonsecaFramework.Sql:

Package Downloads
FonsecaFramework.Aspire

Collection of classes and extensions for .NET Aspire

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.5.21.1 37 5/22/2026
2026.5.20.1 47 5/20/2026
2026.5.12.1 112 5/13/2026
2026.5.11.1 114 5/11/2026
2026.5.7.2 106 5/7/2026
2026.5.7.1 107 5/7/2026
2026.5.6.1 106 5/6/2026
2026.5.5.1 107 5/5/2026
2026.5.2.1 103 5/2/2026
2026.4.30.1 117 4/30/2026
2026.4.29.1 125 4/29/2026
2026.4.27.1 109 4/28/2026
2026.4.22.1 101 4/22/2026
2026.4.21.1 93 4/21/2026
2026.4.20.1 117 4/20/2026
2026.4.15.1 114 4/15/2026
2026.4.13.1 112 4/13/2026
2026.4.10.1 114 4/10/2026
2026.4.8.1 121 4/8/2026
2026.4.7.1 122 4/7/2026
Loading failed