dotnet / dotnet/EntityFramework.Docs

Document that calling HasBaseType((Type)null) is usually wrong

Open
#2,597 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

In the documentation there is a Tip section that says the following.
```
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.
```

I am specifically interested in the following sentence:
```
You can also use .HasBaseType((Type)null) to remove an entity type from the hierarchy
```

I think it would be best for there to be more than just one sentence on this topic. There are no examples of the use cases this provides.

### My specific use case

A specific use case that I am trying to implement is to have 3 entities. 1 base class, and two subclasses. The base class has some default columns that both subclasses need but I don't want the base class has no real use in the database. Right now I am working around this issue by creating a placeholder value called Null in the discriminator enum.

```
public enum EEntityType
{
Null, // I want to get rid of this since the base class is not needed.
SubClass1,
SubClass2,
}
```

Does `.HasBaseType((Type)null)` fill this need? If so I think an example needs to be added to understand the use cases of this method better.

---
#### 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: **ansvyryd**

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.