GennadyGS.SqlQueryBuilder
1.4.1
dotnet add package GennadyGS.SqlQueryBuilder --version 1.4.1
NuGet\Install-Package GennadyGS.SqlQueryBuilder -Version 1.4.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="GennadyGS.SqlQueryBuilder" Version="1.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GennadyGS.SqlQueryBuilder --version 1.4.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GennadyGS.SqlQueryBuilder, 1.4.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.
// Install GennadyGS.SqlQueryBuilder as a Cake Addin #addin nuget:?package=GennadyGS.SqlQueryBuilder&version=1.4.1 // Install GennadyGS.SqlQueryBuilder as a Cake Tool #tool nuget:?package=GennadyGS.SqlQueryBuilder&version=1.4.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SqlQueryBuilder
Utility class for building SQL queries with parameters based on C# string interpolation.
Examples
// Building SQL query with parameters
SqlQueryBuilder queryBuilder = $"SELECT * FROM Orders WHERE Id = {123}";
Assert.Equal(
"SELECT * FROM Orders WHERE Id = @p1",
queryBuilder.GetQuery());
Assert.Equal(
new Dictionary<string, object?> { ["p1"] = 123 },
queryBuilder.GetParameters());
// Composing SQL queries with parameters
SqlQueryBuilder innerQueryBuilder = $"SELECT * FROM Orders WHERE Id = {123}";
SqlQueryBuilder outerQueryBuilder =
$"SELECT * FROM ({innerQueryBuilder}) src WHERE IsValid = {true}";
Assert.Equal(
"SELECT * FROM (SELECT * FROM Orders WHERE Id = @p1) src WHERE IsValid = @p2",
outerQueryBuilder.GetQuery());
Assert.Equal(
new Dictionary<string, object?> { ["p1"] = 123, ["p2"] = true },
outerQueryBuilder.GetParameters());
// Inline table name as literal string by specifying the "l" format
var tableName = "Orders";
SqlQueryBuilder queryBuilder = $"SELECT * FROM {tableName:l} WHERE Id = {123}";
var (query, parameters) = queryBuilder.GetQueryAndParameters();
Assert.Equal("SELECT * FROM Orders WHERE Id = @p1", query);
Assert.Equal(new Dictionary<string, object?> { ["p1"] = 123 }, parameters);
// Building SQL query with specified parameter name prefix
SqlQueryBuilder queryBuilder = $"SELECT * FROM Orders WHERE Id = {123}";
var (query, parameters) = queryBuilder.GetQueryAndParameters("param");
Assert.Equal("SELECT * FROM Orders WHERE Id = @param1", query);
Assert.Equal(new Dictionary<string, object?> { ["param1"] = 123 }, parameters);
// Building SQL query with metadata
var queryBuilder = ((SqlQueryBuilder)$"SELECT * FROM Orders WHERE Id = {123}")
.AddMetadata("DbName", "Db1");
Assert.Equal(
"SELECT * FROM Orders WHERE Id = @p1",
queryBuilder.GetQuery());
Assert.Equal(
new Dictionary<string, object?> { ["p1"] = 123 },
queryBuilder.GetParameters());
Assert.Equal(
new Dictionary<string, object?> { ["DbName"] = "Db1" },
queryBuilder.Metadata);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.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.