Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 902ef2e

Browse files
committed
Update README.md
1 parent 9d186e5 commit 902ef2e

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,26 @@ var track = db.SingleById<Track>(1);
863863
var tracks = db.SelectByIds<Track>(new[]{ 1,2,3 });
864864
```
865865

866+
## Nested Typed Sub SqlExpressions
867+
868+
The `Sql.In()` API supports nesting and combining of multiple Typed SQL Expressions together
869+
in a single SQL Query, e.g:
870+
871+
```csharp
872+
var usaCustomerIds = db.From<Customer>(c => c.Country == "USA").Select(c => c.Id);
873+
var usaCustomerOrders = db.Select(db.From<Order>()
874+
.Where(x => Sql.In(x.CustomerId, usaCustomerIds)));
875+
```
876+
877+
### SQL In Expressions
878+
879+
```csharp
880+
db.Select<Author>(x => Sql.In(x.City, "London", "Madrid", "Berlin"));
881+
882+
var cities = new[] { "London", "Madrid", "Berlin" };
883+
db.Select<Author>(x => Sql.In(x.City, cities));
884+
```
885+
866886
### Parametrized IN Values
867887

868888
OrmLite also supports providing collection of values which is automatically split into multiple DB parameters to simplify executing parameterized SQL with multiple IN Values, e.g:
@@ -875,6 +895,17 @@ var names = new List<string>{ "foo", "bar", "qux" };
875895
var results = db.SqlList<Table>("SELECT * FROM Table WHERE Name IN (@names)", new { names });
876896
```
877897

898+
### Custom SQL using PostgreSQL Arrays
899+
900+
If using PostgreSQL you can take advantage of its complex Array Types and utilize its [Array Functions and Operators](https://www.postgresql.org/docs/9.6/functions-array.html), e.g:
901+
902+
```csharp
903+
var ids = new[]{ 1, 2, 3};
904+
var q = Db.From<Table>()
905+
.And("ARRAY[{0}] && ref_ids", ids.Join(","))
906+
var results = db.Select(q);
907+
```
908+
878909
### Lazy Queries
879910

880911
API's ending with `Lazy` yield an IEnumerable sequence letting you stream the results without having to map the entire resultset into a disconnected List of POCO's first, e.g:
@@ -1634,17 +1665,6 @@ var q = db.From<Table>()
16341665
var results = db.Select(q);
16351666
```
16361667

1637-
## Nested Typed Sub SqlExpressions
1638-
1639-
The `Sql.In()` API supports nesting and combining of multiple Typed SQL Expressions together
1640-
in a single SQL Query, e.g:
1641-
1642-
```csharp
1643-
var usaCustomerIds = db.From<Customer>(c => c.Country == "USA").Select(c => c.Id);
1644-
var usaCustomerOrders = db.Select(db.From<Order>()
1645-
.Where(x => Sql.In(x.CustomerId, usaCustomerIds)));
1646-
```
1647-
16481668
## Optimistic Concurrency
16491669

16501670
Optimistic concurrency can be added to any table by adding the `ulong RowVersion { get; set; }` property, e.g:

0 commit comments

Comments
 (0)