dotnet / dotnet/EntityFramework.Docs

Inheritance page not comprehensive: lacks code snippets and needs more details.

Open
#3,053 1 comment 0 reactions 0 assignees View on GitHub
area-model-building
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

This page only includes how EF Core would configure TPH by default when conventions are relied upon. Information regarding its configuration and customization using the Fluent API is skipped.

For example:
>If you don't want to expose a DbSet for one or more entities in the hierarchy, you can also use the Fluent API to ensure they are included in the model.

In the above statement, *use the Fluent API* is like telling the reader that it can be done but go and find out how its done.
It would be quite useful if ways to explicitly map derived types when not declared as properties in the `DbContext` is demonstrated. Also, it would be great if it is specified that this explicit mapping is not required when child types are assigned a discriminator value using `HasDiscriminator("disc_name").HasValue(value)` .

To take advantage of the polymorphic capabilities of inheritance, it is a very common practice to store references to more derived types in the base class reference. Hence, it is worth mentioning with code snippets how to have a single collection `DbSet` referencing specific types and then using `OfType()` to query for more specific instances and if casting is legal.

The page also does not mention how to configure TPH when the base class is abstract. Neither does it mention if the base class is allowed to be declared abstract in the first place.

Another tip on the page that is a bit vague is:
> If you don't rely on conventions, you can specify the base type explicitly using `HasBaseType`. You can also use `.HasBaseType((Type)null)` to remove an entity type from the hierarchy.

A code snippet here would help a lot,

I would argue that Inheritance in EF Core requires its own section in the documentation and TPT should be moved to its separate page.
Considering that this is the only page dedicated to Inheritance in EF Core, it needs to be comprehensive enough to include common use cases.

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: a10898c5-abee-1843-cfff-b2707f8a079a
* Version Independent ID: d9399618-488e-20b1-f707-35a191b95cc1
* Content: [Inheritance - EF Core](https://docs.microsoft.com/en-us/ef/core/modeling/inheritance)
* Content Source: [entity-framework/core/modeling/inheritance.md](https://github.com/dotnet/EntityFramework.Docs/blob/master/entity-framework/core/modeling/inheritance.md)
* Product: **entity-framework**
* Technology: **entity-framework-core**
* GitHub Login: @AndriySvyryd
* Microsoft Alias: **avickers**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.