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

Commit ebedab9

Browse files
committed
Tweak README to avoid wrapping, rename ev to q
1 parent ebffc2d commit ebedab9

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ To give you a flavour here are some examples with their partial SQL output (usin
5959

6060
```csharp
6161
int agesAgo = DateTime.Today.AddYears(-20).Year;
62-
db.Select<Author>(q => q.Birthday >= new DateTime(agesAgo, 1, 1) && q.Birthday <= new DateTime(agesAgo, 12, 31));
62+
db.Select<Author>(q => q.Birthday >= new DateTime(agesAgo, 1, 1)
63+
&& q.Birthday <= new DateTime(agesAgo, 12, 31));
6364
```
6465

6566
**WHERE (("Birthday" >= '1992-01-01 00:00:00.000') AND ("Birthday" <= '1992-12-31 00:00:00.000'))**
@@ -126,7 +127,8 @@ int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age), x => x.Age < 50)
126127
**SELECT Max("Age") FROM "Person" WHERE ("Age" < 50)**
127128

128129
```csharp
129-
int peopleOver40 = db.Scalar<int>(db.From<Person>().Select(Sql.Count("*")).Where(q => q.Age > 40));
130+
int peopleOver40 = db.Scalar<int>(
131+
db.From<Person>().Select(Sql.Count("*")).Where(q => q.Age > 40));
130132
```
131133

132134
**SELECT COUNT(*) FROM "Person" WHERE ("Age" > 40)**
@@ -229,39 +231,44 @@ db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName);
229231
**UPDATE "Person" SET "FirstName" = 'JJ'**
230232

231233
```csharp
232-
db.UpdateOnly(new Person { FirstName = "JJ", Age = 12 }, p => new { p.FirstName, p.Age });
234+
db.UpdateOnly(new Person { FirstName = "JJ", Age = 12 },
235+
onlyFields: p => new { p.FirstName, p.Age });
233236
```
234237
**UPDATE "Person" SET "FirstName" = 'JJ', "Age" = 12**
235238

236239
When present, the second expression is used as the where filter:
237240
```csharp
238-
db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName, p => p.LastName == "Hendrix");
241+
db.UpdateOnly(new Person { FirstName = "JJ" },
242+
onlyFields: p => p.FirstName,
243+
where: p => p.LastName == "Hendrix");
239244
```
240245
**UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')**
241246

242-
Instead of using the expression filters above you can choose to use an ExpressionVisitor builder which provides more
243-
flexibility when you want to programatically construct the update statement:
247+
Instead of using the expression filters above you can choose to use an ExpressionVisitor builder which provides more flexibility when you want to programatically construct the update statement:
244248

245249
```csharp
246-
db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" }, ev => ev.Update(p => p.FirstName));
250+
db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" },
251+
onlyFields: q => q.Update(p => p.FirstName));
247252
```
248253
**UPDATE "Person" SET "FirstName" = 'JJ'**
249254

250255
```csharp
251-
db.UpdateOnly(new Person { FirstName = "JJ" }, ev => ev.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));
256+
db.UpdateOnly(new Person { FirstName = "JJ" },
257+
onlyFields: q => 1.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));
252258
```
253259
**UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')**
254260

255-
For the ultimate flexibility we also provide un-typed, string-based expressions. Use the `.Params()` extension method
256-
escape parameters (inspired by [massive](https://github.com/robconery/massive)):
261+
For the ultimate flexibility we also provide un-typed, string-based expressions. Use the `.Params()` extension method escape parameters (inspired by [massive](https://github.com/robconery/massive)):
257262

258263
```csharp
259-
db.Update<Person>(set: "FirstName = {0}".Params("JJ"), where: "LastName = {0}".Params("Hendrix"));
264+
db.Update<Person>(set: "FirstName = {0}".Params("JJ"),
265+
where: "LastName = {0}".Params("Hendrix"));
260266
```
261267
Even the Table name can be a string so you perform the same update without requiring the Person model at all:
262268

263269
```csharp
264-
db.Update(table: "Person", set: "FirstName = {0}".Params("JJ"), where: "LastName = {0}".Params("Hendrix"));
270+
db.Update(table: "Person", set: "FirstName = {0}".Params("JJ"),
271+
where: "LastName = {0}".Params("Hendrix"));
265272
```
266273
**UPDATE "Person" SET FirstName = 'JJ' WHERE LastName = 'Hendrix'**
267274

@@ -277,7 +284,7 @@ db.Insert(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 2
277284
But do provide an API that takes an Expression Visitor for the rare cases you don't want to insert every field
278285

279286
```csharp
280-
db.InsertOnly(new Person { FirstName = "Amy" }, ev => ev.Insert(p => new { p.FirstName }));
287+
db.InsertOnly(new Person { FirstName = "Amy" }, q => q.Insert(p => new {p.FirstName} ));
281288
```
282289
**INSERT INTO "Person" ("FirstName") VALUES ('Amy')**
283290

@@ -290,7 +297,7 @@ db.Delete<Person>(p => p.Age == 27);
290297

291298
Or an Expression Visitor:
292299
```csharp
293-
db.Delete<Person>(ev => ev.Where(p => p.Age == 27));
300+
db.Delete<Person>(q => q.Where(p => p.Age == 27));
294301
```
295302

296303
**DELETE FROM "Person" WHERE ("Age" = 27)**
@@ -309,7 +316,7 @@ db.Delete(table: "Person", where: "Age = {0}".Params(27));
309316

310317
# Features
311318

312-
OrmLite's goal is to provide a convenient, DRY, RDBMS-agnostic typed wrapper that retains a high affinity with SQL, exposing an intuitive API that generates predictable SQL and straight-forward mapping to clean disconnected POCO's. This approach makes easier to reason-about your data access as it's obvious what SQL is getting executed at what time, mitigating unexpected behavior, implicit N+1 queries and leaky data access prevalent in Heavy ORMs.
319+
OrmLite's goal is to provide a convenient, DRY, RDBMS-agnostic typed wrapper that retains a high affinity with SQL, exposing an intuitive API that generates predictable SQL and straight-forward mapping to clean, disconnected (DTO-friendly) POCO's. This approach makes easier to reason-about your data access as it's obvious what SQL is getting executed at what time, mitigating unexpected behavior, implicit N+1 queries and leaky data access prevalent in Heavy ORMs.
313320

314321
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:
315322

tests/ServiceStack.OrmLite.Tests/ApiSqlServerTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ public void API_SqlServer_Examples()
250250
db.InsertAll(new[] { new Person { Id = 10, FirstName = "Biggie", LastName = "Smalls", Age = 24 } });
251251
Assert.That(db.GetLastSql(), Is.EqualTo("INSERT INTO \"Person\" (\"Id\",\"FirstName\",\"LastName\",\"Age\") VALUES (@Id,@FirstName,@LastName,@Age)"));
252252

253-
db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, ev => ev.Insert(p => new { p.FirstName, p.Age }));
253+
db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, q => q.Insert(p => new { p.FirstName, p.Age }));
254254
Assert.That(db.GetLastSql(), Is.EqualTo("INSERT INTO \"PersonWithAutoId\" (\"FirstName\",\"Age\") VALUES ('Amy',27)"));
255255

256-
db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, ev => db.From<PersonWithAutoId>().Insert(p => new { p.FirstName, p.Age }));
256+
db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, q => db.From<PersonWithAutoId>().Insert(p => new { p.FirstName, p.Age }));
257257
Assert.That(db.GetLastSql(), Is.EqualTo("INSERT INTO \"PersonWithAutoId\" (\"FirstName\",\"Age\") VALUES ('Amy',27)"));
258258

259259
db.Update(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 });
@@ -285,10 +285,10 @@ public void API_SqlServer_Examples()
285285
db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName, p => p.LastName == "Hendrix");
286286
Assert.That(db.GetLastSql(), Is.EqualTo("UPDATE \"Person\" SET \"FirstName\"='JJ' WHERE (\"LastName\" = 'Hendrix')"));
287287

288-
db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" }, ev => ev.Update(p => p.FirstName));
288+
db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" }, q => q.Update(p => p.FirstName));
289289
Assert.That(db.GetLastSql(), Is.EqualTo("UPDATE \"Person\" SET \"FirstName\"='JJ'"));
290290

291-
db.UpdateOnly(new Person { FirstName = "JJ" }, ev => ev.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));
291+
db.UpdateOnly(new Person { FirstName = "JJ" }, q => q.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));
292292
Assert.That(db.GetLastSql(), Is.EqualTo("UPDATE \"Person\" SET \"FirstName\"='JJ' WHERE (\"FirstName\" = 'Jimi')"));
293293

294294
db.UpdateFmt<Person>(set: "FirstName = {0}".SqlFmt("JJ"), where: "LastName = {0}".SqlFmt("Hendrix"));
@@ -329,7 +329,7 @@ public void API_SqlServer_Examples()
329329
db.Delete<Person>(p => p.Age == 27);
330330
Assert.That(db.GetLastSql(), Is.EqualTo("DELETE FROM \"Person\" WHERE (\"Age\" = 27)"));
331331

332-
db.Delete<Person>(ev => ev.Where(p => p.Age == 27));
332+
db.Delete<Person>(q => q.Where(p => p.Age == 27));
333333
Assert.That(db.GetLastSql(), Is.EqualTo("DELETE FROM \"Person\" WHERE (\"Age\" = 27)"));
334334

335335
db.Delete(db.From<Person>().Where(p => p.Age == 27));

0 commit comments

Comments
 (0)