dotnet / dotnet/EntityFramework.Docs
Ambiguity in documentation of Shadow Property generated for required and optional one to many relationship
- Dominant language
- Mermaid
- Stars
- 1.7k
- Forks
- 2k
- Avg merge
- 7d 23h
- Merged PRs (30d)
- 16
Description
There are a few things related to automatically generated shadow properties mentioned in this documentation have me confused-
First, Question for this [section](https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/modeling/relationships/one-to-many.md)-
1. I don't see any nullable type being used in this example. Is this statement correct-
> An important point to note here is that [C# nullable reference types](https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types) are being used
-------
2. If the generated foreign key property will be nullable by default, making the relationship optional regardless of the nullability of the reference navigation property. How is it fair to say the following if the nullability of reference navigation property has no impact on shadow foreign key property?
> An important point to note here is that [C# nullable reference types](https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types) are being used, so the nullability of the reference navigation is used to determine whether or not the foreign key property is nullable, and therefore whether the relationship is optional or required.
* These 2 statements from the next section prove that whether reference navigation is nullable or non-nullable, shadow foreign key property will be nullable by default, disproving the above statement-
> When C# nullable reference types are not being used, then the foreign key property will also, by default, be created as nullable. This means relationships with automatically created shadow properties are optional by default.
> this time the foreign key property is created as nullable because [C# nullable reference types](https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types) are being used and the navigation on the dependent entity type is nullable. This makes the relationship optional.
----------------
3. If it's true that the foreign key will be nullable when reference navigation is non-nullable, then how can this be true-
> EF therefore creates a [shadow foreign key property](https://learn.microsoft.com/en-us/ef/core/modeling/shadow-properties) called BlogId of type int.
It should create BlogId of type `int?`
These 2 sections have been very confusing to understand and I feel like there is a lot of ambuity here. Can you please shed some light?
Contributor guide
Assessment
This issue has not been assessed yet.