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

Commit 130b4f2

Browse files
committed
replace q => with query or rename to x => where relevant
1 parent 94abe8d commit 130b4f2

File tree

1 file changed

+56
-33
lines changed

1 file changed

+56
-33
lines changed

README.md

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ in a single SQL Query, e.g:
235235
```csharp
236236
var usaCustomerIds = db.From<Customer>(c => c.Country == "USA").Select(c => c.Id);
237237
var usaCustomerOrders = db.Select(db.From<Order>()
238-
.Where(q => Sql.In(q.CustomerId, usaCustomerIds)));
238+
.Where(x => Sql.In(x.CustomerId, usaCustomerIds)));
239239
```
240240

241241
# API Examples
@@ -248,32 +248,32 @@ construct more complex queries. To give you a flavour here are some examples:
248248

249249
```csharp
250250
int agesAgo = DateTime.Today.AddYears(-20).Year;
251-
db.Select<Author>(q => q.Birthday >= new DateTime(agesAgo, 1, 1)
252-
&& q.Birthday <= new DateTime(agesAgo, 12, 31));
251+
db.Select<Author>(x => x.Birthday >= new DateTime(agesAgo, 1, 1)
252+
&& x.Birthday <= new DateTime(agesAgo, 12, 31));
253253
```
254254

255255
```csharp
256-
db.Select<Author>(q => Sql.In(q.City, "London", "Madrid", "Berlin"));
256+
db.Select<Author>(x => Sql.In(x.City, "London", "Madrid", "Berlin"));
257257
```
258258

259259
```csharp
260-
db.Select<Author>(q => q.Earnings <= 50);
260+
db.Select<Author>(x => x.Earnings <= 50);
261261
```
262262

263263
```csharp
264-
db.Select<Author>(q => q.Name.StartsWith("A"));
264+
db.Select<Author>(x => x.Name.StartsWith("A"));
265265
```
266266

267267
```csharp
268-
db.Select<Author>(q => q.Name.EndsWith("garzon"));
268+
db.Select<Author>(x => x.Name.EndsWith("garzon"));
269269
```
270270

271271
```csharp
272-
db.Select<Author>(q => q.Name.Contains("Benedict"));
272+
db.Select<Author>(x => x.Name.Contains("Benedict"));
273273
```
274274

275275
```csharp
276-
db.Select<Author>(q => q.Rate == 10 && q.City == "Mexico");
276+
db.Select<Author>(x => x.Rate == 10 && x.City == "Mexico");
277277
```
278278

279279
### Convenient common usage data access patterns
@@ -290,7 +290,7 @@ Person person = db.Single<Person>(x => x.Age == 42);
290290

291291
```csharp
292292
var q = db.From<Person>()
293-
.Where(q => q.Age > 40)
293+
.Where(x => x.Age > 40)
294294
.Select(Sql.Count("*"));
295295

296296
int peopleOver40 = db.Scalar<int>(q);
@@ -310,15 +310,15 @@ int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age), x => x.Age < 50)
310310

311311
```csharp
312312
var q = db.From<Person>()
313-
.Where(q => q.Age == 27)
313+
.Where(x => x.Age == 27)
314314
.Select(x => x.LastName);
315315

316316
List<string> results = db.Column<string>(q);
317317
```
318318

319319
```csharp
320320
var q = db.From<Person>()
321-
.Where(q => q.Age < 50)
321+
.Where(x => x.Age < 50)
322322
.Select(x => x.Age);
323323

324324
HashSet<int> results = db.ColumnDistinct<int>(q);
@@ -334,7 +334,7 @@ Dictionary<int,string> results = db.Dictionary<int, string>(q);
334334

335335
```csharp
336336
var q = db.From<Person>()
337-
.Where(q => q.Age < 50)
337+
.Where(x => x.Age < 50)
338338
.Select(x => new { x.Age, x.LastName });
339339

340340
Dictionary<int, List<string>> results = db.Lookup<int, string>(q);
@@ -401,14 +401,19 @@ db.UpdateOnly(new Person { FirstName = "JJ" },
401401
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:
402402

403403
```csharp
404-
db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" },
405-
onlyFields: q => q.Update(p => p.FirstName));
404+
var q = db.From<Person>()
405+
.Update(p => p.FirstName);
406+
407+
db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" }, onlyFields: q);
406408
```
407409

408410
Using a typed SQL Expression:
409411

410412
```csharp
411-
var q = db.From<Person>().Update(p => p.FirstName).Where(x => x.FirstName == "Jimi");
413+
var q = db.From<Person>()
414+
.Where(x => x.FirstName == "Jimi")
415+
.Update(p => p.FirstName);
416+
412417
db.UpdateOnly(new Person { FirstName = "JJ" }, onlyFields: q);
413418
```
414419

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

436441
```csharp
437-
db.InsertOnly(new Person { FirstName = "Amy" }, q => q.Insert(p => new {p.FirstName}))
442+
var q = db.From<Person>()
443+
.Insert(p => new { p.FirstName });
444+
445+
db.InsertOnly(new Person { FirstName = "Amy" }, onlyFields: q)
438446
```
439447

440448
### DELETE
@@ -446,7 +454,9 @@ db.Delete<Person>(p => p.Age == 27);
446454

447455
Or an Expression Visitor:
448456
```csharp
449-
var q = db.From<Person>().Where(p => p.Age == 27);
457+
var q = db.From<Person>()
458+
.Where(p => p.Age == 27);
459+
450460
db.Delete<Person>(q);
451461
```
452462

@@ -499,7 +509,7 @@ List<Track> tracks = db.Select<Track>()
499509
**Single** returns a single record:
500510

501511
```csharp
502-
Track track = db.Single<Track>(q => q.RefId == refId)
512+
Track track = db.Single<Track>(x => x.RefId == refId)
503513
```
504514

505515
**Dictionary** returns a Dictionary made from the first two columns:
@@ -590,7 +600,10 @@ Whilst OrmLite aims to provide a light-weight typed wrapper around SQL, it offer
590600
Starting with the most basic example you can simply specify the table you want to join with:
591601

592602
```csharp
593-
var dbCustomers = db.Select<Customer>(q => q.Join<CustomerAddress>());
603+
var q = db.From<Customer>()
604+
.Join<CustomerAddress>();
605+
606+
var dbCustomers = db.Select<Customer>(q);
594607
```
595608

596609
This query rougly maps to the following SQL:
@@ -721,10 +734,10 @@ var customer = new Customer
721734

722735
db.Save(customer, references:true);
723736

724-
var c = db.LoadSelect<Customer>(q => q.Name == "The Customer");
737+
var c = db.LoadSelect<Customer>(x => x.Name == "The Customer");
725738
c.WorkAddress.Address.Print(); // 2 Work Road
726739
727-
var ukAddress = db.Single<CustomerAddress>(q => q.Country == "UK");
740+
var ukAddress = db.Single<CustomerAddress>(x => x.Country == "UK");
728741
ukAddress.Address.Print(); // 2 Work Road
729742
```
730743

@@ -752,7 +765,10 @@ Where `FullCustomerInfo` is any POCO that contains a combination of properties m
752765
The above example is also equivalent to the shorthand `db.Select<Into,From>()` API:
753766

754767
```csharp
755-
var customers = db.Select<FullCustomerInfo,Customer>(q => q.Join<CustomerAddress>());
768+
var q = db.From<Customer>()
769+
.Join<CustomerAddress>();
770+
771+
var customers = db.Select<FullCustomerInfo,Customer>(q);
756772
```
757773

758774
Rules for how results are mapped is simply each property on `FullCustomerInfo` is mapped to the first matching property in any of the tables in the order they were added to the SqlExpression.
@@ -861,7 +877,7 @@ var customer = db.LoadSingleById<Customer>(customerId);
861877
Using Typed SqlExpressions:
862878

863879
```csharp
864-
var customers = db.LoadSelect<Customer>(q => q.Name == "Customer 1");
880+
var customers = db.LoadSelect<Customer>(x => x.Name == "Customer 1");
865881
```
866882

867883
More examples available in [LoadReferencesTests.cs](https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/tests/ServiceStack.OrmLite.Tests/LoadReferencesTests.cs)
@@ -884,10 +900,12 @@ For example you can select a collection of Customers who've made an order with q
884900

885901
```csharp
886902
//Select Customers who've had orders with Quantities of 10 or more
887-
List<Customer> customers = db.Select<Customer>(q =>
888-
q.Join<Order>()
889-
.Where<Order>(o => o.Qty >= 10)
890-
.SelectDistinct());
903+
var q = db.From<Customer>()
904+
.Join<Order>()
905+
.Where<Order>(o => o.Qty >= 10)
906+
.SelectDistinct();
907+
908+
List<Customer> customers = db.Select<Customer>(q);
891909

892910
//Select Orders with Quantities of 10 or more
893911
List<Order> orders = db.Select<Order>(o => o.Qty >= 10);
@@ -1093,7 +1111,7 @@ using (var db = OpenDbConnection())
10931111
db.DropAndCreateTable<PocoTable>();
10941112
db.Insert(new PocoTable { Name = "Multiplicity" });
10951113

1096-
var rowsInserted = db.Count<PocoTable>(q => q.Name == "Multiplicity"); //3
1114+
var rowsInserted = db.Count<PocoTable>(x => x.Name == "Multiplicity"); //3
10971115
}
10981116
```
10991117

@@ -1323,8 +1341,11 @@ For more complex queries you can easily fall back to raw SQL where the Custom SQ
13231341
let you to map custom SqlExpressions into different responses:
13241342

13251343
```csharp
1326-
List<Person> results = db.SqlList<Person>(
1327-
db.From<Person>().Select("*").Where(q => q.Age < 50));
1344+
var q = db.From<Person>()
1345+
.Where(x => x.Age < 50)
1346+
.Select("*");
1347+
List<Person> results = db.SqlList<Person>(q);
1348+
13281349
List<Person> results = db.SqlList<Person>(
13291350
"SELECT * FROM Person WHERE Age < @age", new { age=50});
13301351

@@ -1334,8 +1355,10 @@ List<string> results = db.SqlColumn<string>("SELECT LastName FROM Person");
13341355
HashSet<int> results = db.ColumnDistinct<int>(db.From<Person>().Select(x => x.Age));
13351356
HashSet<int> results = db.ColumnDistinct<int>("SELECT Age FROM Person");
13361357

1337-
int result = db.SqlScalar<int>(
1338-
db.From<Person>().Select(Sql.Count("*")).Where(q => q.Age < 50));
1358+
var q = db.From<Person>()
1359+
.Where(x => x.Age < 50)
1360+
.Select(Sql.Count("*"));
1361+
int result = db.SqlScalar<int>(q);
13391362
int result = db.SqlScalar<int>("SELCT COUNT(*) FROM Person WHERE Age < 50");
13401363
```
13411364

0 commit comments

Comments
 (0)