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
Copy file name to clipboardExpand all lines: docs/usage/resources/relationships.md
+15-3
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,10 @@
1
1
# Relationships
2
2
3
-
In order for navigation properties to be identified in the model,
4
-
they should be labeled with the appropriate attribute (either `HasOne`, `HasMany` or `HasManyThrough`).
3
+
A relationship is a named link between two resource types, including a direction.
4
+
They are similar to [navigation properties in Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/modeling/relationships).
5
+
6
+
Relationships come in three flavors: to-one, to-many and many-to-many.
7
+
The left side of a relationship is where the relationship is declared, the right side is the resource type it points to.
5
8
6
9
## HasOne
7
10
@@ -15,6 +18,9 @@ public class TodoItem : Identifiable
15
18
}
16
19
```
17
20
21
+
The left side of this relationship is of type `TodoItem` (public name: "todoItems") and the right side is of type `Person` (public name: "persons").
22
+
23
+
18
24
## HasMany
19
25
20
26
This exposes a to-many relationship.
@@ -27,11 +33,14 @@ public class Person : Identifiable
27
33
}
28
34
```
29
35
36
+
The left side of this relationship is of type `Person` (public name: "persons") and the right side is of type `TodoItem` (public name: "todoItems").
37
+
38
+
30
39
## HasManyThrough
31
40
32
41
Earlier versions of Entity Framework Core (up to v5) [did not support](https://github.com/aspnet/EntityFrameworkCore/issues/1368) many-to-many relationships without a join entity.
33
42
For this reason, we have decided to fill this gap by allowing applications to declare a relationship as `HasManyThrough`.
34
-
JsonApiDotNetCore will expose this relationship to the client the same way as any other `HasMany`attribute.
43
+
JsonApiDotNetCore will expose this relationship to the client the same way as any other `HasMany`relationship.
35
44
However, under the covers it will use the join type and Entity Framework Core's APIs to get and set the relationship.
36
45
37
46
```c#
@@ -49,6 +58,9 @@ public class Article : Identifiable
49
58
}
50
59
```
51
60
61
+
The left side of this relationship is of type `Article` (public name: "articles") and the right side is of type `Tag` (public name: "tags").
62
+
63
+
52
64
## Name
53
65
54
66
There are two ways the exposed relationship name is determined:
Copy file name to clipboardExpand all lines: test/JsonApiDotNetCoreExampleTests/IntegrationTests/Microservices/TransactionalOutboxPattern/OutboxTests.Group.cs
Copy file name to clipboardExpand all lines: test/JsonApiDotNetCoreExampleTests/IntegrationTests/Microservices/TransactionalOutboxPattern/OutboxTests.User.cs
0 commit comments