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

Commit fbc827f

Browse files
committed
Extend reference docs
1 parent 1b411b5 commit fbc827f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,41 @@ class CustomerAddress {
479479
}
480480
```
481481

482+
### Self References
483+
484+
Self References are also supported for **1:1** relations where the Foreign Key can instead be on the parent table:
485+
486+
```csharp
487+
public class Customer
488+
{
489+
...
490+
public int CustomerAddressId { get; set; }
491+
492+
[Reference]
493+
public CustomerAddress PrimaryAddress { get; set; }
494+
}
495+
```
496+
497+
### Foreign Key and References Attributes
498+
499+
References that don't follow the above naming conventions can be declared explicitly using
500+
the `[References]` and `[ForeignKey]` attributes:
501+
502+
```csharp
503+
public class Customer
504+
{
505+
[References(typeof(CustomerAddress))]
506+
public int PrimaryAddressId { get; set; }
507+
508+
[Reference]
509+
public CustomerAddress PrimaryAddress { get; set; }
510+
}
511+
```
512+
513+
> Reference Attributes take precedence over naming conventions
514+
515+
### Implicit Reference Conventions are applied by default
516+
482517
The implicit relationship above allows you to use any of these equilvalent APIs to JOIN tables:
483518

484519
```csharp

0 commit comments

Comments
 (0)