From ccfcee4bf341409c87de19462c7dd554d8699a9b Mon Sep 17 00:00:00 2001 From: "toan.pn" Date: Fri, 16 May 2025 21:25:09 +0700 Subject: [PATCH] Add remarks to Navigation methods in EntityTypeBuilder and OwnedNavigationBuilder --- .../Metadata/Builders/EntityTypeBuilder.cs | 4 ++ .../Builders/OwnedNavigationBuilder.cs | 4 ++ src/EFCore/Properties/CoreStrings.resx | 56 +++++++++---------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs index efd2c13823d..34f8ac2677a 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs @@ -773,6 +773,10 @@ public virtual EntityTypeBuilder ComplexCollection(Type propertyType, string pro /// /// The name of the navigation property to be configured. /// An object that can be used to configure the navigation property. + /// + /// Navigation properties must first be added to the entity type using methods like HasOne, HasMany, + /// or OwnsOne/OwnsMany before they can be configured with this method. + /// public virtual NavigationBuilder Navigation(string navigationName) => new(Builder.Navigation(Check.NotEmpty(navigationName, nameof(navigationName)))); diff --git a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs index 6ddaacdea7e..20ffeeaa2af 100644 --- a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs @@ -304,6 +304,10 @@ public virtual PropertyBuilder IndexerProperty( /// /// The name of the navigation property to be configured. /// An object that can be used to configure the navigation property. + /// + /// Navigation properties must first be added to the entity type using methods like HasOne, WithOwner, + /// or OwnsOne/OwnsMany before they can be configured with this method. + /// public virtual NavigationBuilder Navigation(string navigationName) => new( DependentEntityType.Builder.Navigation( diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 93f0363df2c..441726f0347 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -1,17 +1,17 @@  - @@ -238,7 +238,7 @@ Unable to create an instance of entity type '{entityType}' because it is abstract. Consider making make it non-abstract or mapping at least one derived type. - Navigation '{1_entityType}.{0_navigationName}' was not found. Please add the navigation to the entity type before configuring it. + Navigation '{1_entityType}.{0_navigationName}' was not found. Please add the navigation to the entity type using HasOne, HasMany, or OwnsOne/OwnsMany methods before configuring it. The entity type '{entityType}' is configured to use the '{changeTrackingStrategy}' change tracking strategy, but does not implement the required '{notificationInterface}' interface. Implement '{notificationInterface}' on '{entityType}' or use a different change tracking strategy.