SQLQueryCommandBuilder 1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SQLQueryCommandBuilder --version 1.0.1
NuGet\Install-Package SQLQueryCommandBuilder -Version 1.0.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="SQLQueryCommandBuilder" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SQLQueryCommandBuilder --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SQLQueryCommandBuilder, 1.0.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 SQLQueryCommandBuilder as a Cake Addin
#addin nuget:?package=SQLQueryCommandBuilder&version=1.0.1
// Install SQLQueryCommandBuilder as a Cake Tool
#tool nuget:?package=SQLQueryCommandBuilder&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Git Documentation [Github] ("https://bitbucket.org/sql-commandquery-builder/sqlquerycommandbuilder/src/master/README.md" )
public class user
{
public user()
{
}
[SQLResolver(PrimaryKeyName = "id")]
public int id { get; set; }
public int age { get; set; }
public string name { get; set; }
public bool isActive { get; set; }
}
Primary key must have SQLResolver Attribute with the property name as PrimaryKeyName value
SQL Query Resolver Extension Methods
1. string Query<T>(this T obj, BuilderOptions options = null)
2.string Query<T>(this T obj, List<string> selectColumns, BuilderOptions options = null)
3. string Query<T>(this T obj, Expression<Func<T, bool>> whereClause, List<string> selectColumns = null, BuilderOptions options = null)
4. Query<T>(this T obj, int rows, int offset = 0, Expression<Func<T, bool>> whereClause = null, List<string> selectColumns = null, BuilderOptions options = null)
Sample Codes
Example 1
var sql = new user().Query<user>()
Output
SELECT * FROM user
Example 2
var sql = new user().Query<user>(
whereClause: x => ((x.name == "oscar" && x.isActive == true) || x.age > 20),
options: new SQL.QueryBuilder.Options.BuilderOptions
{
orderBy = SQL.QueryBuilder.Enums.OrderBy.ASC,
orderByColumn = "age"
});
Output
SELECT * FROM user Where ((([name] = 'oscar') AND ([isActive] = True)) OR ([age] > 20)) ORDER BY age ASC
Example 3
var sql = new user().Query<user>(
whereClause: x => ((x.name == "oscar" && x.isActive == true) || x.age > 20),
options: new SQL.QueryBuilder.Options.BuilderOptions
{
orderBy = SQL.QueryBuilder.Enums.OrderBy.ASC,
orderByColumn = "age"
},
selectColumns: new List<string>() { "age", "name" }
);
Output
SELECT age,name FROM user Where ((([name] = 'oscar') AND ([isActive] = True)) OR ([age] > 20)) ORDER BY age ASC
Example 4
var items = new List<int>() { 3, 6, 3, 2 };
var test2 = new user().Query<user>(rows: 20, offset: 0,
selectColumns: new List<string>() { "age", "name" },
whereClause: x => x.name.Contains("oscar") && items.Contains(x.id)
);
Output
SELECT age,name FROM user Where (nolock) (([name] LIKE '%oscar%') AND ([id] IN (3,6,3,2))) OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY
Supported Lamda Expression Operations
Input | Output |
---|---|
x ⇒ x.id == 1 | ([id] = 1) |
x ⇒ x.isAcrive | ([isAcrive] = 1) |
x ⇒ !x.isAcrive | (NOT ([isAcrive] = 1)) |
x ⇒ x.name == null | ([name] IS NULL) |
x ⇒ x.id == id | (where id = 2) ([id] = 2) |
x ⇒ x.id == 1 && x.name == "Main" | (([id] = 1) AND ([Name] = 'Main')) |
x ⇒ x.name.Contains(“Main”) | ([name] LIKE ‘%Main%’) |
x ⇒ x.name.StartsWith(“R”) | ([name] LIKE 'R%') |
x ⇒ list.Contains(x.id) | ([id] IN (1, 2, 3)) |
x ⇒ x.id == 1 !! x.name == "Main" | (([id] = 1) OR ([Name] = 'Main')) |
SQL Command Resolver Extension Methods
1. string Insert<T>(this T obj)
2. string Update<T>(this T obj, Expression<Func<T, bool>> whereClause, List<string> selectColums = null)
3. string Delete<T>(this T obj, Expression<Func<T, bool>> whereClause)
Sample Codes
Example 1
var sql = new user().Insert<user>();
Output
INSERT INTO user (age,name,isActive) VALUES (@age,@name,@isActive)
Example 2
var items = new List<int>() { 3, 6, 3, 2 };
var sql = new user().Update<user>(
whereClause: x => x.name.Contains("oscar") && items.Contains(x.id);
Output
UPDATE user SET age=@age,name=@name,isActive=@isActive Where (([name] LIKE '%oscar%') AND ([id] IN (3,6,3,2)))
Example 3
var items = new List<int>() { 3, 6, 3, 2 };
var sql = new user().Delete<user>(
whereClause: x => x.name.Contains("oscar") && items.Contains(x.id));
Output
DELETE FROM user Where (([name] LIKE '%oscar%') AND ([id] IN (3,6,3,2)))
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- 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.