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

Commit 94abe8d

Browse files
committed
Remove deprecated APIs from README
1 parent c734a67 commit 94abe8d

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

README.md

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,19 @@ db.Select<Author>(q => q.Rate == 10 && q.City == "Mexico");
281281
OrmLite also includes a number of convenient API's providing DRY, typed data access for common queries:
282282

283283
```csharp
284-
Person personById = db.SingleById<Person>(1);
284+
Person person = db.SingleById<Person>(1);
285285
```
286286

287287
```csharp
288-
Person personByAge = db.Single<Person>(x => x.Age == 42);
288+
Person person = db.Single<Person>(x => x.Age == 42);
289289
```
290290

291291
```csharp
292-
int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age), x => x.Age < 50);
293-
```
292+
var q = db.From<Person>()
293+
.Where(q => q.Age > 40)
294+
.Select(Sql.Count("*"));
294295

295-
```csharp
296-
int peopleOver40 = db.Scalar<int>(
297-
db.From<Person>().Select(Sql.Count("*")).Where(q => q.Age > 40));
296+
int peopleOver40 = db.Scalar<int>(q);
298297
```
299298

300299
```csharp
@@ -306,23 +305,39 @@ bool has42YearOlds = db.Exists<Person>(new { Age = 42 });
306305
```
307306

308307
```csharp
309-
List<string> results = db.Column<string>(db.From<Person>().Select(x => x.LastName)
310-
.Where(q => q.Age == 27));
308+
int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age), x => x.Age < 50);
309+
```
310+
311+
```csharp
312+
var q = db.From<Person>()
313+
.Where(q => q.Age == 27)
314+
.Select(x => x.LastName);
315+
316+
List<string> results = db.Column<string>(q);
311317
```
312318

313319
```csharp
314-
HashSet<int> results = db.ColumnDistinct<int>(db.From<Person>().Select(x => x.Age)
315-
.Where(q => q.Age < 50));
320+
var q = db.From<Person>()
321+
.Where(q => q.Age < 50)
322+
.Select(x => x.Age);
323+
324+
HashSet<int> results = db.ColumnDistinct<int>(q);
316325
```
317326

318327
```csharp
319-
Dictionary<int,string> results = db.Dictionary<int, string>(
320-
db.From<Person>().Select(x => new { x.Id, x.LastName }).Where(x => x.Age < 50));
328+
var q = db.From<Person>()
329+
.Where(x => x.Age < 50)
330+
.Select(x => new { x.Id, x.LastName });
331+
332+
Dictionary<int,string> results = db.Dictionary<int, string>(q);
321333
```
322334

323335
```csharp
324-
Dictionary<int, List<string>> results = db.Lookup<int, string>(
325-
db.From<Person>().Select(x => new { x.Age, x.LastName }).Where(q => q.Age < 50));
336+
var q = db.From<Person>()
337+
.Where(q => q.Age < 50)
338+
.Select(x => new { x.Age, x.LastName });
339+
340+
Dictionary<int, List<string>> results = db.Lookup<int, string>(q);
326341
```
327342

328343
### INSERT, UPDATE and DELETEs
@@ -332,10 +347,10 @@ To see the behaviour of the different APIs, all examples uses this simple model
332347
```csharp
333348
public class Person
334349
{
335-
public int Id { get; set; }
336-
public string FirstName { get; set; }
337-
public string LastName { get; set; }
338-
public int? Age { get; set; }
350+
public int Id { get; set; }
351+
public string FirstName { get; set; }
352+
public string LastName { get; set; }
353+
public int? Age { get; set; }
339354
}
340355
```
341356

@@ -393,21 +408,21 @@ db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" },
393408
Using a typed SQL Expression:
394409

395410
```csharp
396-
db.UpdateOnly(new Person { FirstName = "JJ" },
397-
onlyFields: q => q.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));
411+
var q = db.From<Person>().Update(p => p.FirstName).Where(x => x.FirstName == "Jimi");
412+
db.UpdateOnly(new Person { FirstName = "JJ" }, onlyFields: q);
398413
```
399414

400415
For the ultimate flexibility we also provide un-typed, string-based expressions. Use the `.SqlFmt()` extension method escape parameters (inspired by [massive](https://github.com/robconery/massive)):
401416

402417
```csharp
403418
db.UpdateFmt<Person>(set: "FirstName = {0}".SqlFmt("JJ"),
404-
where: "LastName = {0}".SqlFmt("Hendrix"));
419+
where: "LastName = {0}".SqlFmt("Hendrix"));
405420
```
406421
Even the Table name can be a string so you perform the same update without requiring the Person model at all:
407422

408423
```csharp
409424
db.UpdateFmt(table: "Person", set: "FirstName = {0}".SqlFmt("JJ"),
410-
where: "LastName = {0}".SqlFmt("Hendrix"));
425+
where: "LastName = {0}".SqlFmt("Hendrix"));
411426
```
412427
### INSERT
413428

@@ -431,7 +446,8 @@ db.Delete<Person>(p => p.Age == 27);
431446

432447
Or an Expression Visitor:
433448
```csharp
434-
db.Delete<Person>(q => q.Where(p => p.Age == 27));
449+
var q = db.From<Person>().Where(p => p.Age == 27);
450+
db.Delete<Person>(q);
435451
```
436452

437453
As well as un-typed, string-based expressions:
@@ -565,7 +581,6 @@ var topVIPs = db.SelectLazyFmt<Person>("Age > {0}", 40).Where(p => IsVip(p)).Tak
565581
- `Save` and `SaveAll` will Insert if no record with **Id** exists, otherwise it Updates.
566582
- Methods containing the word **Each** return an IEnumerable<T> and are lazily loaded (i.e. non-buffered).
567583

568-
569584
# Features
570585

571586
Whilst OrmLite aims to provide a light-weight typed wrapper around SQL, it offers a number of convenient features that makes working with RDBMS's a clean and enjoyable experience:

0 commit comments

Comments
 (0)