CommonNetFuncs.Sql.Common
4.0.15
dotnet add package CommonNetFuncs.Sql.Common --version 4.0.15
NuGet\Install-Package CommonNetFuncs.Sql.Common -Version 4.0.15
<PackageReference Include="CommonNetFuncs.Sql.Common" Version="4.0.15" />
<PackageVersion Include="CommonNetFuncs.Sql.Common" Version="4.0.15" />
<PackageReference Include="CommonNetFuncs.Sql.Common" />
paket add CommonNetFuncs.Sql.Common --version 4.0.15
#r "nuget: CommonNetFuncs.Sql.Common, 4.0.15"
#:package CommonNetFuncs.Sql.Common@4.0.15
#addin nuget:?package=CommonNetFuncs.Sql.Common&version=4.0.15
#tool nuget:?package=CommonNetFuncs.Sql.Common&version=4.0.15
CommonNetFuncs.Sql.Common
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>
Installation
Install via NuGet:
dotnet add package CommonNetFuncs.Sql.Common
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- CommonNetFuncs.Core (>= 4.0.15)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on CommonNetFuncs.Sql.Common:
| Package | Downloads |
|---|---|
|
CommonNetFuncs.Sql.Odbc
ODBC driver companion for CommonNetFuncs.Sql.Common |
|
|
CommonNetFuncs.Web.Interface
Helper methods that deal with ASP.NET Core interfaces |
|
|
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 |
|---|---|---|
| 4.0.15 | 110 | 2/8/2026 |
| 4.0.14 | 103 | 2/7/2026 |
| 4.0.12 | 113 | 2/3/2026 |
| 4.0.10 | 118 | 1/24/2026 |
| 4.0.9 | 126 | 1/12/2026 |
| 4.0.6 | 131 | 1/2/2026 |
| 4.0.3 | 228 | 12/22/2025 |
| 4.0.2 | 707 | 12/2/2025 |
| 4.0.1 | 220 | 11/27/2025 |
| 4.0.0 | 349 | 11/23/2025 |
| 3.8.33 | 145 | 2/2/2026 |
| 3.8.32 | 137 | 2/2/2026 |
| 3.8.28 | 159 | 1/5/2026 |
| 3.8.20 | 640 | 12/1/2025 |
| 3.8.18 | 463 | 11/20/2025 |
| 3.8.16 | 457 | 11/17/2025 |
| 3.8.13 | 352 | 11/10/2025 |
| 3.8.4 | 251 | 10/9/2025 |
| 3.7.23 | 255 | 9/23/2025 |
| 3.7.17 | 248 | 9/11/2025 |