CSQLQueryExpress 1.4.1
See the version list below for details.
dotnet add package CSQLQueryExpress --version 1.4.1
NuGet\Install-Package CSQLQueryExpress -Version 1.4.1
<PackageReference Include="CSQLQueryExpress" Version="1.4.1" />
paket add CSQLQueryExpress --version 1.4.1
#r "nuget: CSQLQueryExpress, 1.4.1"
// Install CSQLQueryExpress as a Cake Addin #addin nuget:?package=CSQLQueryExpress&version=1.4.1 // Install CSQLQueryExpress as a Cake Tool #tool nuget:?package=CSQLQueryExpress&version=1.4.1
CSQLQueryExpress
CSQLQueryExpress is a C# library designed to compile TSQL code, providing developers with the utmost flexibility to write expressions in C# that closely resemble TSQL syntax.
Note that while CSQLQueryExpress handles the compilation of TSQL code, the execution is delegated to any ORM such as Dapper.
Example
Here's a simple example to demonstrate how to use CSQLQueryExpress with Dapper:
using CSQLQueryExpress;
using Dapper;
using System.Data.SqlClient;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
class Program
{
static void Main()
{
SQLQuerySelect<Users> query =
new SQLQuery()
.From<Users>()
.Where(u => u.Age.IsNotNull() && u.Age > 30)
.Select(u => u.All());
var tSqlQuery = query.Compile();
var statement = tSqlQuery.Statement; //"SELECT _t0.* FROM [dbo].[Users] AS _t0 WHERE ((_t0.[Age] IS NOT NULL) AND (_t0.[Age] > @p0))"
var parameters = tSqlQuery.ParametersKeyValue; //@p0 = 30
using (var connection = new SqlConnection("YourConnectionString"))
{
connection.Open();
var result = connection.Query<Users>(statement, parameters);
foreach (var user in result)
{
Console.WriteLine($"UserID:{user.UserID} - FirstName:{user.FirstName} - LastName:{user.LastName} - Age:{user.Age}");
}
}
}
}
[Table("Users", Schema = "dbo")]
public class Users : ISQLQueryEntity
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("EmployeeID")]
public int UserID { get; set; }
[Required]
[Column("FirstName")]
public string FirstName { get; set; }
[Required]
[Column("LastName")]
public string LastName { get; set; }
[Column("Age")]
public int? Age { get; set; }
}
TSQL
Some functions and statements supported by CSQLQueryExpress:
Scalar Functions:
- Mathematical Functions:
ABS
: Returns the absolute value of a number.CEILING
: Returns the smallest integer greater than or equal to a number.FLOOR
: Returns the largest integer less than or equal to a number.ROUND
: Rounds a number to a specified number of decimal places.SQRT
: Returns the square root of a number.
- String Functions:
LEN
: Returns the length of a string.LOWER
: Converts a string to lowercase.UPPER
: Converts a string to uppercase.SUBSTRING
: Extracts a portion of a string.REPLACE
: Replaces all occurrences of a substring within a string.LTRIM
/RTRIM
: Removes leading or trailing spaces from a string.LEFT
/RIGHT
: Returns characters from the left or right part of a string.
- Date and Time Functions:
DATEADD
: Adds an interval to a date.DATEDIFF
: Returns the difference between two dates.DATEPART
: Returns a specified part of a date as an integer.DATEFROMPARTS
: Returns a date from year, month, and day values.SYSDATETIME
: Returns a system datetime.TIMEFROMPARTS
: Returns a time value for the specified time and with the specified precision.EOMONTH
: Returns the last day of the month containing a specified date, with an optional offset.CONVERT
: Converts a date to a specified format.
- Logical Functions:
ISNULL
: Replaces NULL with a specified replacement value.
- Aggregate Functions:
SUM
: Calculates the sum of a set of values.AVG
: Calculates the average of a set of values.MIN
/MAX
: Returns the minimum or maximum value in a set of values.COUNT
: Returns the number of values in a set.
Statements and Constructs:
CTE
: Common Table Expression.SUBQUERY
STORED PROCEDURE
VIEW
EXISTS
: Checks if a subquery returns any rows.BETWEEN
: Selects values within a given range.FOR XML
: Returns the query result as XML.CASE
: Returns different values based on conditional logic.BATCH
: A group of two or more SQL statements executed before any results.MULTIPLE RESULT SETS
: A feature that works with SQL Server to allow the execution of multiple batches on a single connection.TABLE HINTS
: Used to override the default behavior of the query optimizer during the data manipulation language (DML) statement.JOIN HINTS
: Specify that the query optimizer enforce a join strategy between two tables.OUTPUT
withINSERTED
andDELETED
: Returns the rows affected by anINSERT
,UPDATE
, orDELETE
statement.INSERTED
: Holds the new values being inserted or updated.DELETED
: Holds the old values being deleted or updated.
Do you have a comprehensive list of examples?
CSQLQueryExpress has a comprehensive test suite in the test project.
CSQLQueryExpress.Scaffolding
CSQLQueryExpress.Scaffolding is a C# NuGet library designed to compile the data model for CSQLQueryExpress from the database schema.
Note
Compile and verify generated statements from the library: Compile and test the TSQL statements generated by the library. The library translates the query you write respecting the expressions used. Some expressions can be used in different contexts, the library is not able to discern the intention of the writer, therefore the control both in the writing and verification phases lies with the developer.
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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.4.5 | 91 | 11/21/2024 |
1.4.4 | 69 | 11/21/2024 |
1.4.3 | 74 | 11/21/2024 |
1.4.2 | 67 | 11/21/2024 |
1.4.1 | 66 | 11/21/2024 |
1.4.0 | 73 | 11/20/2024 |
1.3.8 | 75 | 11/20/2024 |
1.3.7 | 67 | 11/20/2024 |
1.3.6 | 65 | 11/20/2024 |
1.3.5 | 69 | 11/20/2024 |
1.3.4 | 452 | 8/8/2024 |
1.3.3 | 66 | 7/30/2024 |
1.3.1 | 110 | 7/18/2024 |
1.3.0 | 90 | 7/11/2024 |
1.2.6 | 95 | 7/10/2024 |
1.2.5 | 108 | 7/9/2024 |
1.2.4 | 96 | 7/8/2024 |
1.2.3 | 109 | 7/7/2024 |
1.2.2 | 104 | 7/3/2024 |
1.2.1 | 93 | 7/2/2024 |
1.2.0 | 102 | 7/1/2024 |
1.1.8 | 110 | 6/14/2024 |
1.1.7 | 107 | 6/13/2024 |
1.1.6 | 110 | 6/12/2024 |
1.1.5 | 96 | 6/12/2024 |
1.1.4 | 92 | 6/11/2024 |
1.1.3 | 90 | 6/11/2024 |
1.1.2 | 79 | 6/10/2024 |
1.1.1 | 94 | 6/10/2024 |
1.1.0 | 77 | 6/10/2024 |