@@ -282,7 +282,7 @@ db.Insert(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 2
282
282
But do provide an API that takes an Expression Visitor for the rare cases you don't want to insert every field
283
283
284
284
``` csharp
285
- db .InsertOnly (new Person { FirstName = " Amy" }, q => q .Insert (p => new {p .FirstName } ));
285
+ db .InsertOnly (new Person { FirstName = " Amy" }, q => q .Insert (p => new {p .FirstName }))
286
286
```
287
287
** INSERT INTO "Person" ("FirstName") VALUES ('Amy')**
288
288
@@ -593,7 +593,7 @@ public class CustomerAddress
593
593
{
594
594
[AutoIncrement ]
595
595
public int Id { get ; set ; }
596
- public int CustomerId { get ; set ; } // `{Parent}Id` convention to reference Customer
596
+ public int CustomerId { get ; set ; } // `{Parent}Id` convention to refer to Customer
597
597
public string AddressLine1 { get ; set ; }
598
598
public string AddressLine2 { get ; set ; }
599
599
public string City { get ; set ; }
@@ -605,7 +605,7 @@ public class Order
605
605
{
606
606
[AutoIncrement ]
607
607
public int Id { get ; set ; }
608
- public int CustomerId { get ; set ; } // `{Parent}Id` convention to reference Customer
608
+ public int CustomerId { get ; set ; } // `{Parent}Id` convention to refer to Customer
609
609
public string LineItem { get ; set ; }
610
610
public int Qty { get ; set ; }
611
611
public decimal Cost { get ; set ; }
@@ -784,7 +784,9 @@ The Result Filters also lets you easily mock results and avoid hitting the datab
784
784
``` csharp
785
785
using (new OrmLiteResultsFilter {
786
786
PrintSql = true ,
787
- SingleResult = new Person { Id = 1 , FirstName = " Mocked" , LastName = " Person" , Age = 100 },
787
+ SingleResult = new Person {
788
+ Id = 1 , FirstName = " Mocked" , LastName = " Person" , Age = 100
789
+ },
788
790
})
789
791
{
790
792
db .Single <Person >(x => x .Age == 42 ).FirstName // Mocked
@@ -998,16 +1000,19 @@ OrmLite's T4 support can be added via NuGet with:
998
1000
The Custom SQL API's allow you to map custom SqlExpressions into different responses:
999
1001
1000
1002
``` csharp
1001
- List < Person > results = db .SqlList <Person >(db .From <Person >().Select (" *" ).Where (q => q .Age < 50 ));
1002
- List < Person > results = db .SqlList <Person >(" SELECT * FROM Person WHERE Age < @age" , new { age = 50 });
1003
+ List < Person > results = db .SqlList <Person >(
1004
+ db .From <Person >().Select (" *" ).Where (q => q .Age < 50 ));
1005
+ List < Person > results = db .SqlList <Person >(
1006
+ " SELECT * FROM Person WHERE Age < @age" , new { age = 50 });
1003
1007
1004
1008
List < string > results = db .SqlColumn <string >(db .From <Person >().Select (x => x .LastName ));
1005
1009
List < string > results = db .SqlColumn <string >(" SELECT LastName FROM Person" );
1006
1010
1007
1011
HashSet < int > results = db .ColumnDistinct <int >(db .From <Person >().Select (x => x .Age ));
1008
1012
HashSet < int > results = db .ColumnDistinct <int >(" SELECT Age FROM Person" );
1009
1013
1010
- int result = db .SqlScalar <int >(db .From <Person >().Select (Sql .Count (" *" )).Where (q => q .Age < 50 ));
1014
+ int result = db .SqlScalar <int >(
1015
+ db .From <Person >().Select (Sql .Count (" *" )).Where (q => q .Age < 50 ));
1011
1016
int result = db .SqlScalar <int >(" SELCT COUNT(*) FROM Person WHERE Age < 50" );
1012
1017
```
1013
1018
@@ -1018,10 +1023,12 @@ executing Stored Procedures:
1018
1023
1019
1024
``` csharp
1020
1025
List < Poco > results = db .SqlList <Poco >(" EXEC GetAnalyticsForWeek 1" );
1021
- List < Poco > results = db .SqlList <Poco >(" EXEC GetAnalyticsForWeek @weekNo" , new { weekNo = 1 });
1026
+ List < Poco > results = db .SqlList <Poco >(
1027
+ " EXEC GetAnalyticsForWeek @weekNo" , new { weekNo = 1 });
1022
1028
1023
1029
List < int > results = db .SqlList <int >(" EXEC GetTotalsForWeek 1" );
1024
- List < int > results = db .SqlList <int >(" EXEC GetTotalsForWeek @weekNo" , new { weekNo = 1 });
1030
+ List < int > results = db .SqlList <int >(
1031
+ " EXEC GetTotalsForWeek @weekNo" , new { weekNo = 1 });
1025
1032
1026
1033
int result = db .SqlScalar <int >(" SELECT 10" );
1027
1034
```
@@ -1462,30 +1469,30 @@ public class ShipperTypeCount
1462
1469
Creating tables is a simple 1-liner:
1463
1470
1464
1471
``` csharp
1465
- using (IDbConnection db = " :memory:" .OpenDbConnection ())
1466
- {
1467
- db .CreateTable <ShipperType >();
1468
- db .CreateTable <Shipper >();
1469
- }
1470
-
1471
- /* In debug mode the line above prints:
1472
- DEBUG: CREATE TABLE "ShipperTypes"
1473
- (
1474
- "ShipperTypeID" INTEGER PRIMARY KEY AUTOINCREMENT,
1475
- "Name" VARCHAR(40) NOT NULL
1476
- );
1477
- DEBUG: CREATE UNIQUE INDEX uidx_shippertypes_name ON "ShipperTypes" ("Name" ASC);
1478
- DEBUG: CREATE TABLE "Shippers"
1479
- (
1480
- "ShipperID" INTEGER PRIMARY KEY AUTOINCREMENT,
1481
- "CompanyName" VARCHAR(40) NOT NULL,
1482
- "Phone" VARCHAR(24) NULL,
1483
- "ShipperTypeId" INTEGER NOT NULL,
1484
-
1485
- CONSTRAINT "FK_Shippers_ShipperTypes" FOREIGN KEY ("ShipperTypeId") REFERENCES "ShipperTypes" ("ShipperID")
1486
- );
1487
- DEBUG: CREATE UNIQUE INDEX uidx_shippers_companyname ON "Shippers" ("CompanyName" ASC);
1488
- */
1472
+ using (IDbConnection db = " :memory:" .OpenDbConnection ())
1473
+ {
1474
+ db .CreateTable <ShipperType >();
1475
+ db .CreateTable <Shipper >();
1476
+ }
1477
+
1478
+ /* In debug mode the line above prints:
1479
+ DEBUG: CREATE TABLE "ShipperTypes"
1480
+ (
1481
+ "ShipperTypeID" INTEGER PRIMARY KEY AUTOINCREMENT,
1482
+ "Name" VARCHAR(40) NOT NULL
1483
+ );
1484
+ DEBUG: CREATE UNIQUE INDEX uidx_shippertypes_name ON "ShipperTypes" ("Name" ASC);
1485
+ DEBUG: CREATE TABLE "Shippers"
1486
+ (
1487
+ "ShipperID" INTEGER PRIMARY KEY AUTOINCREMENT,
1488
+ "CompanyName" VARCHAR(40) NOT NULL,
1489
+ "Phone" VARCHAR(24) NULL,
1490
+ "ShipperTypeId" INTEGER NOT NULL,
1491
+
1492
+ CONSTRAINT "FK_Shippers_ShipperTypes" FOREIGN KEY ("ShipperTypeId") REFERENCES "ShipperTypes" ("ShipperID")
1493
+ );
1494
+ DEBUG: CREATE UNIQUE INDEX uidx_shippers_companyname ON "Shippers" ("CompanyName" ASC);
1495
+ */
1489
1496
```
1490
1497
1491
1498
### Transaction Support
0 commit comments