Skip to content

Commit

Permalink
fix: typo in Optional one-to-one (#4325)
Browse files Browse the repository at this point in the history
  • Loading branch information
NAVAL authored Apr 20, 2023
1 parent d1ac480 commit 0809a1b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion entity-framework/core/modeling/relationships/one-to-one.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Neither of these options is better than the other; they both result in exactly t
-->
[!code-csharp[OneToOneOptionalShadow](../../../../samples/core/Modeling/Relationships/OneToOne.cs?name=OneToOneOptionalShadow)]

In some cases, you may not want a foreign key property in your model, since foreign keys are a detail of how the relationship is represented in the database, which is not needed whe using the relationship in a purely object-oriented manner. However, if entities are going to be serialized, for example to send over a wire, then the foreign key values can be a useful way to keep the relationship information intact when the entities are not in an object form. It is therefore often pragmatic to keep foreign key properties in the .NET type for this purpose. Foreign key properties can be private, which is often a good compromise to avoid exposing the foreign key while allowing its value to travel with the entity.
In some cases, you may not want a foreign key property in your model, since foreign keys are a detail of how the relationship is represented in the database, which is not needed when using the relationship in a purely object-oriented manner. However, if entities are going to be serialized, for example to send over a wire, then the foreign key values can be a useful way to keep the relationship information intact when the entities are not in an object form. It is therefore often pragmatic to keep foreign key properties in the .NET type for this purpose. Foreign key properties can be private, which is often a good compromise to avoid exposing the foreign key while allowing its value to travel with the entity.

This is the same as the previous example, except that the foreign key property and navigation to the principal are now nullable. This makes the relationship "optional" because a dependent (`BlogHeader`) can _not_ be related _any_ principal (`Blog`) by setting its foreign key property and navigation to `null`.

Expand Down

0 comments on commit 0809a1b

Please sign in to comment.