Operators¶
Comparison operators¶
IOperator op1 = sql.Eq(person["Id"], 1);
IOperator op2 = sql.Eq(() => person.Id, 1);
// SqlExtensions
IOperator op3 = person["Id"].Eq(1);
IOperator op4 = sql.Col(() => person.Id).Eq(1);
// Lambda expression
IOperator op5 = sql.Op(() => person.Id == 1);
Logical operators¶
IOperator op1 = sql.And
.Add(sql.Eq(person["Active"], true))
.Add(sql.Ge(person["Salary"], 2000));
// Lambda overload
IOperator op2 = sql.Or
.Add(() => person.Active)
.Add(() => person.Salary >= 2000);
// Lambda expression
IOperator op3 = sql.Op(() => person.Active && person.Salary >= 2000);
Arithmetic operators¶
IOperator op1 = sql.Add
.Add(person["Salary"])
.Add(200);
// Lambda overload
IOperator op2 = sql.Add
.Add(() => person.Salary)
.Add(200);
// Lambda expression
// Because is not a boolean result must call "Val" instead of "Op"
IOperator op3 = sql.Val(() => person.Salary + 200);
Bitwise operators¶
IOperator op1 = sql.BitAnd
.Add(2)
.Add(3);
// Lambda overload
IOperator op2 = sql.Add
.Add(() => 2)
.Add(3);
// Lambda expression
// Because is not a boolean result must call "Val" instead of "Op"
IOperator op3 = sql.Val(() => 2 & 3);
Set operators¶
IOperator op = sql.Union(
sql.Query.Select(() => person.Name).From(() => person),
sql.Query.Select(() => dept.Name).From(() => dept));
List of operators¶
The following list shows the implemented operators:
| SQL | ISqlBuilder | Extensions1 | Expressions | SqlExp |
|---|---|---|---|---|
| = | Eq | Eq | == | Eq |
| <> | NotEq | NotEq | != | NotEq |
| LIKE | Like | Like | Like2 | Like |
| NOT LIKE | NotLike | NotLike | NotLike2 | NotLike |
| < | Lt | Lt | < | Lt |
| <= | Le | Le | <= | Le |
| > | Gt | Gt | > | Gt |
| >= | Ge | Ge | >= | Ge |
| IN | In | In | In3 | In |
| NOT IN | NotIn | NotIn | NotIn3 | NotIn |
| NOT | Not | Not | ! | Not |
| IS NULL | IsNull Eq(null) |
IsNull Eq(null) |
== null | IsNull Eq(null) |
| IS NOT NULL | IsNotNull NotEq(null) |
IsNotNull NotEq(null) |
!= null | IsNotNull NotEq(null) |
| BETWEEN | Between | Between | Between | |
| NOT BETWEEN | NotBetween | NotBetween | NotBetween | |
| AND | And | && & |
||
| OR | Or | || | |
||
| + | Add | Plus | + | |
| - | Subtract | Minus | - | |
| * | Multiply | Multiply | * | |
| / | Divide | Divide | / | |
| % | Modulo | Modulo | % | |
| + (Positive) | + | |||
| - (Negative) | Negate | Negate | - | |
| & | BitAnd | BitAnd | & | |
| | | BitOr | BitOr | | | |
| ^ | BitXor | BitXor | ^ | |
| ~ | BitNot | BitNot | ~ | |
| << | LeftShift | LeftShift | << | |
| >> | RightShift | RightShift | >> | |
| ALL | All | All | ||
| ANY | Any | Any | ||
| EXISTS | Exists | Exists | ||
| SOME | Some | Some | ||
| UNION | Union | |||
| UNION ALL | UnionAll | |||
| EXCEPT | Except | |||
| EXCEPT ALL | ExceptAll | |||
| INTERSECT | Intersect | |||
| INTERSECT ALL | IntersectAll | |||
| CASE | ?: | |||
| COALESCE() | ?? | |||
| CONCAT() | + |
Like pattern¶
You can use the following methods to apply a like pattern:
| Pattern | ISqlBuilder | Extensions4 |
|---|---|---|
| Value% | ToLikeStart | ToLikeStart |
| %Value | ToLikeEnd | ToLikeEnd |
| %Value% | ToLikeAny | ToLikeAny |
IAlias person = sql.Alias("person");
IOperator op = person["Name"].Like(sql.ToLikeAny("SomeName"));
// Extension method
IOperator op = person["Name"].Like("SomeName".ToLikeAny());
Register operators¶
In your engine¶
You can register your operators in your engine to translate them with a different name or into a function.