You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 24, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+41-49Lines changed: 41 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,13 +38,13 @@ Effectively this allows you to create a table from any POCO type and it should p
38
38
39
39
_Latest v4+ on NuGet is a commercial release with [free quotas](https://servicestack.net/download#free-quotas)._
40
40
41
-
### [Docs and Downloads for older v3 BSD releases](https://github.com/ServiceStackV3/ServiceStackV3)
41
+
####[Docs and Downloads for older v3 BSD releases](https://github.com/ServiceStackV3/ServiceStackV3)
42
42
43
-
## Copying
43
+
###Copying
44
44
45
45
Since September 2013, ServiceStack source code is available under GNU Affero General Public License/FOSS License Exception, see license.txt in the source. Alternative [commercial licensing](https://servicestack.net/ormlite) is also available.
46
46
47
-
## Contributing
47
+
###Contributing
48
48
49
49
Contributors need to approve the [Contributor License Agreement](https://docs.google.com/forms/d/16Op0fmKaqYtxGL4sg7w_g-cXXyCoWjzppgkuqzOeKyk/viewform) before any code will be reviewed, see the [Contributing wiki](https://github.com/ServiceStack/ServiceStack/wiki/Contributing) for more details.
50
50
@@ -343,16 +343,14 @@ To better illustrate the above query, lets expand it to the equivalent explicit
The above query joins together the `Customer` and `CustomerAddress` POCO's using the same relationship convention used in [OrmLite's support for References](https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/tests/ServiceStack.OrmLite.Tests/LoadReferencesTests.cs), i.e. using the referenced table `{ParentType}Id` property convention.
354
-
355
-
An example of what this looks like can be seen the POCO's below:
353
+
The above query implicitly joins together the `Customer` and `CustomerAddress` POCO's using the same `{ParentType}Id` property convention used in [OrmLite's support for References](https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/tests/ServiceStack.OrmLite.Tests/LoadReferencesTests.cs), e.g:
356
354
357
355
```csharp
358
356
classCustomer {
@@ -381,21 +379,17 @@ class CustomerAddress {
381
379
}
382
380
```
383
381
384
-
Going back to the above example:
382
+
The implicit relationship above allows you to use any of these equilvalent APIs to JOIN tables:
385
383
386
384
```csharp
387
385
q.Join<CustomerAddress>();
388
-
```
389
-
390
-
Uses the implicit join in the above reference convention to expand into the equivalent explicit API:
### Selecting multiple columns across joined tables
397
391
398
-
Another behaviour implicit when selecting from a typed SqlExpression is that results are mapped to the `Customer` POCO. To change this default we just need to explicitly specify what POCO it should map to instead:
392
+
Another implicit behaviour when selecting from a typed SqlExpression is that results are mapped to the `Customer` POCO. To change this default we just need to explicitly specify what POCO it should map to instead:
@@ -414,40 +408,39 @@ Rules for how results are mapped is simply each property on `FullCustomerInfo` i
414
408
415
409
The mapping also includes a fallback for referencing fully-qualified names in the format: `{TableName}{FieldName}` allowing you to reference ambiguous fields, e.g:
416
410
417
-
-`CustomerId` => `Customer`.`Id`
418
-
-`OrderId` => `Order`.`Id`
419
-
-`CustomerName` => `Customer`.`Name`
420
-
-`OrderCost` => `Order`.`Cost`
411
+
-`CustomerId` => "Customer"."Id"
412
+
-`OrderId` => "Order"."Id"
413
+
-`CustomerName` => "Customer"."Name"
414
+
-`OrderCost` => "Order"."Cost"
421
415
422
416
### Advanced Example
423
417
424
418
Seeing how the SqlExpression is constructed, joined and mapped, we can take a look at a more advanced example to showcase more of the new API's available:
425
419
426
420
```csharp
427
-
List<FullCustomerInfo>rows=db.Select<FullCustomerInfo>( // Map results to FullCustomerInfo POCO
OrmLite's reference support lets Store and Load related entities with the `[Reference]` attribute, e.g:
443
+
OrmLite lets you Store and Load related entities in separate tables using `[Reference]` attributes in primary tables in conjunction with `{Parent}Id` property convention in child tables, e.g:
451
444
452
445
```csharp
453
446
publicclassCustomer
@@ -456,18 +449,18 @@ public class Customer
456
449
publicintId { get; set; }
457
450
publicstringName { get; set; }
458
451
459
-
[Reference]
452
+
[Reference]// Save in CustomerAddress table
460
453
publicCustomerAddressPrimaryAddress { get; set; }
461
454
462
-
[Reference]
455
+
[Reference]// Save in Order table
463
456
publicList<Order> Orders { get; set; }
464
457
}
465
458
466
459
publicclassCustomerAddress
467
460
{
468
461
[AutoIncrement]
469
462
publicintId { get; set; }
470
-
publicintCustomerId { get; set; } // `{Table}Id` convention used for parent references
This lets you save a POCO and all its entity references with `db.Save()`, e.g:
482
+
With the above structure you can save a POCO and all its entity references with `db.Save(T,references:true)`, e.g:
490
483
491
484
```csharp
492
485
varcustomer=newCustomer {
@@ -504,24 +497,23 @@ var customer = new Customer {
504
497
db.Save(customer, references:true);
505
498
```
506
499
507
-
This saves the parent customer POCO in the `Customer` table, the PrimaryAddress in the `CustomerAddress` table as well as 2 Orders in the `Order` table.
500
+
This saves the root customer POCO in the `Customer` table, its related PrimaryAddress in the `CustomerAddress` table and its 2 Orders in the `Order` table.
508
501
509
502
More examples available in [LoadReferencesTests.cs](https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/tests/ServiceStack.OrmLite.Tests/LoadReferencesTests.cs)
510
503
511
504
Unlike normal complex properties, references:
512
505
513
-
- Doesn't persist as complex type blob
506
+
- Doesn't persist as complex type blobs
514
507
- Doesn't impact normal querying
515
508
- Saves and loads references independently from itself
516
-
- Populated references get serialized in Text serializers (only populated are visible).
OrmLite's core Exec functions makes it possible to inject a custom managed exec function where you can inject your own behavior, tracing, profiling, etc.
564
+
OrmLite's core Exec filters makes it possible to inject your own behavior, tracing, profiling, etc.
573
565
574
-
It's useful in situations when you want to use SqlServer in production but use an `in-memory` Sqlite database in tests and you want to emulate any missing SQL Server Stored Procedures in code:
566
+
It's useful in situations like wanting to use SqlServer in production but use an `in-memory` Sqlite database in tests and being able to emulate any missing SQL Server Stored Procedures in code:
@@ -622,7 +614,7 @@ public class CaptureSqlFilter : OrmLiteResultsFilter
622
614
}
623
615
```
624
616
625
-
That can now wrap around existing database calls to capture, defer or print generated SQL, e.g:
617
+
Which can be used to wrap around existing database calls to capture, defer or print generated SQL, e.g:
626
618
627
619
```csharp
628
620
using (varcaptured=newCaptureSqlFilter())
@@ -640,7 +632,7 @@ using (var db = OpenDbConnection())
640
632
641
633
## Mockable extension methods
642
634
643
-
The Result Filters also lets you easily mock results return by OrmLite which it uses instead of hitting the database, typically useful in Unit Testing Services to mock OrmLite API's directly instead of using a repository, e.g:
635
+
The Result Filters also lets you easily mock results and avoid hitting the database, typically useful in Unit Testing Services to mock OrmLite API's directly instead of using a repository, e.g:
0 commit comments