Update README with loading types.
This commit is contained in:
parent
fc9d89ae97
commit
fd6e601489
24
README.md
24
README.md
@ -123,10 +123,32 @@ The following states are tracked in the `EntityState.State` property:
|
|||||||
|
|
||||||
The `Find` functions require tracking, instead, use the `First` function, with a lambda for the ID.
|
The `Find` functions require tracking, instead, use the `First` function, with a lambda for the ID.
|
||||||
|
|
||||||
|
### Loading types
|
||||||
|
|
||||||
|
Entity Framework Core has 3 common loading patterns.
|
||||||
|
|
||||||
|
* **Eager loading**: related data is loaded from the database as part of the initial query.
|
||||||
|
* **Explicit loading**: related data is explicitly loaded from the database later.
|
||||||
|
* **Lazy loading**: related data is loaded from the database accessing navigation property.
|
||||||
|
|
||||||
|
#### Eager loading
|
||||||
|
|
||||||
|
Uses the `include()` function to load related data in a query. The eager loading of a collection navigation may cause a performance issue, use `AsSplitQuery()` as needed to boost performance with large data sets. The `include()` function allows the `Where()` function to be used for filtering. If *tracking* is enabled, then the filter may return *incorrect* data, because it returns tracked records. Data may already be updated in the database, while the application is still using tracked data. Use the `ThenInclude()` function to get more dependencies.
|
||||||
|
|
||||||
|
### Explicit loading
|
||||||
|
|
||||||
|
Data can be explicitly loaded by executing a separate query that returns related entities. If *tracking* is enabled, the navigation properties of the newly loaded entity will refer to any entities already loaded.
|
||||||
|
|
||||||
|
### Lazy loading
|
||||||
|
|
||||||
|
This is the least recommended method of loading data. It requires the [Microsoft.EntityFrameworkCore.Proxies](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Proxies/9.0.3) package. It must then be enabled in the DbContext configuration with `UseLazyLoadingProxies()`. Navigation properties must be virtual. It can cause extra database roundtrips, causing the [N+1 problem](https://docs.sentry.io/product/issues/issue-details/performance-issues/n-one-queries/).
|
||||||
|
|
||||||
## Database
|
## Database
|
||||||
|
|
||||||
### Relationships
|
### Relationships
|
||||||
|
|
||||||
* A **League** has one or more **Teams** (1:M)
|
* A **League** has one or more **Teams** (1:M)
|
||||||
* A **Team** has one **Coach** (1:1)
|
* A **Team** has one **Coach** (1:1)
|
||||||
* **Matches** are played by many **Teams** (M:M)
|
* **Matches** are played by many **Teams** (M:M)
|
||||||
|
|
||||||
|
You can use [EF Core Power Tools](https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools) to create diagrams.
|
||||||
Loading…
x
Reference in New Issue
Block a user