Skip to content

Commit

Permalink
Updates from Andriy's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Mar 28, 2023
1 parent 642ba73 commit df7b4ba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion entity-framework/core/modeling/relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Relationships defined in the model can be used in various ways. For example:
- [Eagerly](xref:core/querying/related-data/eager) as part of a LINQ query, using `Include`.
- [Lazily](xref:core/querying/related-data/lazy) using lazy-loading proxies, or lazy-loading without proxies.
- [Explicitly](xref:core/querying/related-data/explicit) using the `Load` or `LoadAsync` methods.
- Relationships can be used in [data seeding](xref:core/modeling/data-seeding).
- Relationships can be used in [data seeding](xref:core/modeling/data-seeding) through matching of PK values to FK values.
- Relationships can be used to [track graphs of entities](xref:core/change-tracking/index). Relationships are then used by the change tracker to:
- [Detect changes in relationships and perform fixup](xref:core/change-tracking/relationship-changes)
- [Send foreign key updates to the database](xref:core/saving/related-data) with `SaveChanges` or `SaveChangesAsync`
6 changes: 5 additions & 1 deletion entity-framework/core/modeling/relationships/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Once the navigations for a relationship have either been discovered or configure
- `<navigation property name>Id`
- `<principal entity type name><principal key property name>`
- `<principal entity type name>Id`
- In addition, if the dependent end has been explicitly configured using the model building API, and the dependent primary key is compatible, then the dependent primary key will also be used as the foreign key.

> [!TIP]
> The "Id" suffix can have any casing.
Expand Down Expand Up @@ -297,7 +298,7 @@ If EF has determined the dependent end of the relationship but no foreign key pr

## Cascade delete

By convention, non-nullable foreign key properties are configured to [cascade delete](xref:core/saving/cascade-delete). Nullable foreign key properties are configured to not cascade delete.
By convention, required relationships are configured to [cascade delete](xref:core/saving/cascade-delete). Optional relationships are configured to not cascade delete.

## Many-to-many

Expand Down Expand Up @@ -428,6 +429,9 @@ For composite foreign keys, an index is created covering all the foreign key col
CREATE INDEX "IX_Post_ContainingBlogId1_ContainingBlogId2" ON "Post" ("ContainingBlogId1", "ContainingBlogId2");
```

> [!NOTE]
> EF does not create indexes for properties that are already covered by an existing index or primary key constraint.
### How to stop EF creating indexes for foreign keys

Indexes have overhead, and, [as asked here](https://github.com/dotnet/efcore/issues/10855), it may not always be appropriate to create them for all FK columns. To achieve this, the `ForeignKeyIndexConvention` can be removed when building the model:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ By convention, EF creates a database index for the property or properties of a f
## Principal keys

By convention, foreign keys are constrained to the primary key at the principal end of the relationship. However, an alternate key can be used instead. This is achieved using `HasPrincipalKey` on the model building API. For Example, for a single property foreign key:
By convention, foreign keys are constrained to the primary key at the principal end of the relationship. However, an alternate key can be used instead. This is achieved using `HasPrincipalKey` on the model building API. For example, for a single property foreign key:

<!--
protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand Down

0 comments on commit df7b4ba

Please sign in to comment.