Define an alias for the models, to use in queries.
var t0 = new Orders().AsQueryable();
"Sql Commands" (such as AS, AVG, DISTINCT etc.) can be used via helper parameter that comes with expression function.
Odb.SQL.Select(x => ... x[table-field].SqlCommand ... );
CONSTANT
Selects a contant value.
Odb.SQL.Select(x =>
x.Fields( 5.60, x[5.63].AS("C1"),
"str1", x["str2"].AS("C2"),
)
);
AS
Renames a column with an alias.
Odb.SQL.Select(x =>
x.From(t0)
.Fields( x["X"].AS("C1"),
x[t0.OrderID].AS("OID")
)
);
IN / NOT_IN
IN command allows you to specify multiple values in a WHERE clause.
var vals1 = new[] {1, 2};
var vals2 = new[] {"A", "B", "C"};
Odb.SQL.Select(x =>
x.From(t0)
.Where( x[t0.OrderID].IN(vals1) &
x[t0.EmployeeID].NOT_IN(vals2)
)
);
IS NULL / IS NOT NULL
Odb.SQL.Select(x =>
x.From(t0)
.Where( (object)t0.OrderID == DBNull.Value &
(object)t0.EmployeeID != DBNull.Value
)
);
LIKE
is used in a WHERE clause to search for a specified pattern in a column.
Odb.SQL.Select(x =>
x.From(t0)
.Where( x[t0.Country].STARTS_WITH("A") |
x[t0.Country].ENDS_WITH("Z") |
x[t0.Country].CONTAINS("M")
)
);
DISTINCT
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
The DISTINCT statement is used to return only distinct (different) values.
Odb.SQL.Select(x =>
x.From(t0)
.Fields( x[t0.Country].DISTINCT().AS("C") )
);
COALESCE
Return the first non-null value in a list.
Odb.SQL.Select(x =>
x.From(t0)
.Fields( x[t0.CustomerName].COALESCE('???').AS("C") )
);
Aggregate Functions
Odb.SQL.Select(x =>
x.From(t0)
.GroupBy(t0.Country)
.Fields( th.Country,
x[t0.CustomerID].AVG().AS("C1"),
x[t0.CustomerID].MIN().AS("C2"),
x[t0.CustomerID].MAX().AS("C3"),
x[t0.CustomerID].SUM().AS("C4")
)
);
String Functions
Odb.SQL.Select(x =>
x.From(t0)
.Fields( x[t0.City].SUBSTRING(2, 4).AS("2_to_4"),
x[t0.City].SUBSTRING(0, 1).AS("left_1"),
x[t0.City].SUBSTRING(-1, 2).AS("right_2"),
x[t0.City].UPPER().AS("C1"),
x[t0.City].LOWER().AS("C2"),
x[t0.City].TRIM().AS("C3"),
x[t0.City].RTRIM().LTRIM().AS("C4"),
x[t0.City].CONCAT(", ID=", t0.CustomerID).AS("C5")
)
);