CommonNetFuncs.Sql.Common 3.5.0

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

CommonNetFuncs.Sql.Common

nuget

This project contains helper methods for executing SQL queries and commands.

Contents


DirectQuery

Helper methods for executing SQL queries and commands directly against a database.

DirectQuery Usage Examples

<details> <summary><h3>Usage Examples</h3></summary>

GetDataTable

Executes a SELECT query asynchronously and returns the results as a DataTable.

await using SqliteCommand cmd = _connection.CreateCommand();
cmd.CommandText = "SELECT * FROM TestTable";
using DataTable queryResultsTable = await DirectQuery.GetDataTable(connString, cmd); // queryResultsTable will contain the results of the query
GetDataTableSynchronous

Executes a SELECT query synchronously and returns the results as a DataTable.

using SqliteCommand cmd = _connection.CreateCommand();
cmd.CommandText = "SELECT * FROM TestTable";
using DataTable queryResultsTable = DirectQuery.GetDataTable(_connection, cmd); // queryResultsTable will contain the results of the query
RunUpdateQuery

Executes an UPDATE, INSERT, or DELETE query asynchronously and returns an UpdateResult containing the number of affected rows and a boolean indicating success.

await using SqliteCommand cmd = _connection.CreateCommand();
cmd.CommandText = "UPDATE TestTable SET Name = 'Updated' WHERE Name LIKE 'Test%'";
UpdateResult updateResult = await DirectQuery.RunUpdateQuery(_connection, cmd); // { RecordsChanged = 1, Success = true }
RunUpdateQuerySynchronous

Executes an UPDATE, INSERT, or DELETE query synchronously and returns an UpdateResult containing the number of affected rows and a boolean indicating success.

using SqliteCommand cmd = _connection.CreateCommand();
cmd.CommandText = "UPDATE TestTable SET Name = 'Updated' WHERE Name LIKE 'Test%'";
UpdateResult updateResult = DirectQuery.RunUpdateQuery(_connection, cmd); // { RecordsChanged = 1, Success = true }
GetDataStreamSynchronous

Gets a data from a query synchronously and returns an IEnumerable of the query result type.

using SqliteCommand cmd = _connection.CreateCommand();
cmd.CommandText = "SELECT * FROM TestTable";
IEnumerable<TestEntity> queryResults = DirectQuery.GetDataStream(_connection, cmd); // queryResults will contain the results of the query as TestEntity objects
GetDataStreamAsync

Gets a data from a query asynchronously and returns an IAsyncEnumerable of the query result type.

List<TestModel> results = new();
using SqliteCommand cmd = _connection.CreateCommand();
cmd.CommandText = "SELECT * FROM TestTable";
await foreach (TestModel item in DirectQuery.GetDataStreamAsync<TestModel>(_connection, cmd))
{
    results.Add(item); // Results will contain all items returned by the query
}
GetDataDirectAsync

Gets a data from a query asynchronously and returns an IEnumerable of the query result type.

using SqliteCommand cmd = _connection.CreateCommand();
cmd.CommandText = "SELECT * FROM TestTable";
IEnumerable<TestEntity> queryResults = await DirectQuery.GetDataDirectAsync(_connection, cmd); // queryResults will contain the results of the query as TestEntity objects

</details>


QueryParameters

Helper class for cleaning query parameters. Please note that parameter cleaning is not a substitute for proper parameterization of SQL queries. This class is intended to be used in conjunction with parameterized queries to ensure that parameters are clean and safe.

QueryParameters Usage Examples

<details> <summary><h3>Usage Examples</h3></summary>

CleanQueryParam

Cleans potential issues out of a query parameter or query parameters, replacing standalone text "null" with null value or removing any new line characters and extra spaces

"\ntest\n ".CleanQueryParam(); // "test"
IsClean

Checks to make sure that a query parameter does not contain a set of potentially problematic characters / strings including but not limited to: ; ', [, ], ", /*, */ xp_, --, and `

"text[".IsClean(); // false
SanitizeSqlParameter

Sanitizes a SQL parameter by escaping legal but potentially problematic characters or returns and empty string if rules are violated.

string result = "test'name".SanitizeSqlParameter(false, false, false, null, null); // "test''name"
string result = "test;name".SanitizeSqlParameter(false, false, false, null, null); // ""

</details>

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 (4)

Showing the top 4 NuGet packages that depend on CommonNetFuncs.Sql.Common:

Package Downloads
CommonNetFuncs.Web.Interface

Helper methods that deal with ASP.NET Core interfaces

CommonNetFuncs.Sql.Odbc

ODBC driver companion for CommonNetFuncs.Sql.Common

CommonNetFuncs.Sql.PostgreSql

PostgreSQL driver companion for CommonNetFuncs.Sql.Common

CommonNetFuncs.Sql.SqlServer

SQL Server driver companion for CommonNetFuncs.Sql.Common

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.6.19 92 7/28/2025
3.6.18 317 7/25/2025
3.6.6 436 7/21/2025
3.6.1 154 7/14/2025
3.6.0 168 7/14/2025
3.5.3 152 7/10/2025
3.5.0 166 7/7/2025
3.4.23 159 6/26/2025
3.4.21 152 6/26/2025
3.4.20 160 6/25/2025
3.4.18 184 6/23/2025
3.4.14 144 6/17/2025
3.4.9 308 6/11/2025
3.4.8 300 6/11/2025
3.4.2 169 6/2/2025
3.4.1 107 5/30/2025
3.4.0 137 5/30/2025
3.3.11 171 5/19/2025
3.3.10 259 5/13/2025
3.3.0 180 4/29/2025
3.2.22 218 3/12/2025
3.2.14 140 2/20/2025
3.2.13 136 2/13/2025
3.2.9 131 2/4/2025
3.2.6 122 1/28/2025
3.2.0 165 12/19/2024
3.1.0 179 12/6/2024
3.0.0 140 12/3/2024
2.1.3 126 12/3/2024
2.1.2 110 12/3/2024
2.1.0 135 12/2/2024
2.0.5 139 11/26/2024
2.0.2 143 11/18/2024
2.0.1 127 11/15/2024
2.0.0 130 11/14/2024
1.0.47 141 11/14/2024
1.0.42 179 11/12/2024
1.0.40 152 11/12/2024
1.0.37 148 11/4/2024
1.0.31 148 10/31/2024
1.0.28 150 10/25/2024
1.0.26 179 10/18/2024
1.0.25 146 10/17/2024
1.0.24 119 10/17/2024
1.0.18 155 10/11/2024
1.0.17 191 9/27/2024
1.0.16 145 9/27/2024
1.0.14 166 9/23/2024
1.0.13 168 9/18/2024
1.0.12 140 9/18/2024
1.0.11 148 9/18/2024
1.0.10 188 9/11/2024
1.0.9 178 9/11/2024
1.0.8 186 9/11/2024
1.0.7 177 9/11/2024
1.0.2 145 9/10/2024
1.0.1 189 9/4/2024
1.0.0 155 9/2/2024