From 9541bd64233662d4fcef2a8e051a3aa593bef994 Mon Sep 17 00:00:00 2001 From: AndriySvyryd Date: Fri, 27 Mar 2020 23:54:30 -0700 Subject: [PATCH] Make AnnotatableBuilder public Rename InternalRelationshipBuilder to InternalForeignKeyBuilder --- .../Extensions/RelationalModelExtensions.cs | 1 - .../Metadata/Builders/DbFunctionBuilder.cs | 4 - .../Builders/DbFunctionParameterBuilder.cs | 3 - .../Metadata/Builders/SequenceBuilder.cs | 4 - .../IConventionDbFunctionParameter.cs | 10 +- .../Metadata/IDbFunctionParameter.cs | 2 +- .../Metadata/IMutableDbFunctionParameter.cs | 4 +- .../Metadata/Internal/DbFunction.cs | 6 +- .../Metadata/Internal/DbFunctionParameter.cs | 2 - .../Internal/InternalDbFunctionBuilder.cs | 8 +- .../InternalDbFunctionParameterBuilder.cs | 6 +- .../Internal/InternalSequenceBuilder.cs | 7 +- .../Internal/MigrationsModelDiffer.cs | 9 +- .../Infrastructure/AnnotatableBuilder.cs | 223 ++++++++++++++++ .../Infrastructure/ConventionAnnotatable.cs | 8 +- .../Builders/CollectionNavigationBuilder.cs | 18 +- .../Metadata/Builders/EntityTypeBuilder.cs | 6 +- .../Metadata/Builders/EntityTypeBuilder`.cs | 12 +- .../InvertibleRelationshipBuilderBase.cs | 8 +- .../Builders/OwnedNavigationBuilder.cs | 10 +- .../Builders/OwnedNavigationBuilder`.cs | 10 +- .../Metadata/Builders/OwnershipBuilder.cs | 2 +- .../Metadata/Builders/OwnershipBuilder`.cs | 2 +- .../Builders/ReferenceCollectionBuilder.cs | 10 +- .../Builders/ReferenceCollectionBuilder`.cs | 2 +- .../Builders/ReferenceNavigationBuilder.cs | 26 +- .../Builders/ReferenceReferenceBuilder.cs | 18 +- .../Builders/ReferenceReferenceBuilder`.cs | 2 +- .../Builders/RelationshipBuilderBase.cs | 8 +- .../Internal/ConventionBatchExtensions.cs | 6 +- src/EFCore/Metadata/Internal/ForeignKey.cs | 4 +- .../Internal/InternalAnnotatableBuilder.cs | 248 ------------------ .../Internal/InternalAnnotatableBuilder`.cs | 41 --- .../Internal/InternalEntityTypeBuilder.cs | 66 ++--- ...uilder.cs => InternalForeignKeyBuilder.cs} | 127 ++++----- .../Metadata/Internal/InternalIndexBuilder.cs | 3 +- .../Metadata/Internal/InternalKeyBuilder.cs | 3 +- .../Metadata/Internal/InternalModelBuilder.cs | 4 +- .../Internal/InternalModelItemBuilder.cs | 39 --- .../Internal/InternalPropertyBaseBuilder`.cs | 3 +- .../InternalServicePropertyBuilder.cs | 3 +- .../Internal/InternalSkipNavigationBuilder.cs | 6 +- .../Metadata/Internal/RelationshipSnapshot.cs | 6 +- .../AnnotatableBuilderTest.cs} | 14 +- ...reignKeyPropertyDiscoveryConventionTest.cs | 4 +- .../NavigationAttributeConventionTest.cs | 6 +- .../NonNullableNavigationConventionTest.cs | 2 +- .../ValueGeneratorConventionTest.cs | 2 +- 48 files changed, 450 insertions(+), 568 deletions(-) create mode 100644 src/EFCore/Infrastructure/AnnotatableBuilder.cs delete mode 100644 src/EFCore/Metadata/Internal/InternalAnnotatableBuilder.cs delete mode 100644 src/EFCore/Metadata/Internal/InternalAnnotatableBuilder`.cs rename src/EFCore/Metadata/Internal/{InternalRelationshipBuilder.cs => InternalForeignKeyBuilder.cs} (97%) delete mode 100644 src/EFCore/Metadata/Internal/InternalModelItemBuilder.cs rename test/EFCore.Tests/{Metadata/Internal/InternalMetadataBuilderTest.cs => Infrastructure/AnnotatableBuilderTest.cs} (81%) diff --git a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs index 85f15411aaa..0f0857e66c5 100644 --- a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs index 312d82e25a9..ef830172b1f 100644 --- a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs @@ -43,9 +43,7 @@ IConventionDbFunctionBuilder IInfrastructure.Insta /// /// The function being configured. /// -#pragma warning disable EF1001 // Internal EF Core API usage. public virtual IMutableDbFunction Metadata => Builder.Metadata; -#pragma warning restore EF1001 // Internal EF Core API usage. /// /// Sets the name of the database function. @@ -110,9 +108,7 @@ public virtual DbFunctionBuilder HasTranslation([NotNull] Func The parameter name. /// The builder to use for further parameter configuration. public virtual DbFunctionParameterBuilder HasParameter([NotNull] string name) -#pragma warning disable EF1001 // Internal EF Core API usage. => new DbFunctionParameterBuilder(Builder.HasParameter(name, ConfigurationSource.Explicit).Metadata); -#pragma warning restore EF1001 // Internal EF Core API usage. #region Hidden System.Object members diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs index f4975f3c187..f5bc4da8143 100644 --- a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs @@ -6,7 +6,6 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Builders @@ -48,9 +47,7 @@ IConventionDbFunctionParameterBuilder IInfrastructure /// The function parameter metadata that is being built. /// -#pragma warning disable EF1001 // Internal EF Core API usage. public virtual IMutableDbFunctionParameter Metadata => Builder.Metadata; -#pragma warning restore EF1001 // Internal EF Core API usage. /// /// Sets the store type of the function parameter in the database. diff --git a/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs b/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs index 64b9a4a5dbc..9e93a85e8cd 100644 --- a/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs @@ -1,10 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.ComponentModel; using System.Diagnostics; -using System.Linq; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; @@ -40,9 +38,7 @@ IConventionSequenceBuilder IInfrastructure.Instance /// /// The sequence. /// -#pragma warning disable EF1001 // Internal EF Core API usage. public virtual IMutableSequence Metadata => Builder.Metadata; -#pragma warning restore EF1001 // Internal EF Core API usage. /// /// Sets the to increment by the given amount when generating each next value. diff --git a/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs index 0be28d1b609..79a374f5956 100644 --- a/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs @@ -8,7 +8,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata { /// - /// Represents a by-convention database function parameter in an . + /// Represents a parameter. /// public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFunctionParameter { @@ -18,7 +18,7 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun new IConventionDbFunction Function { get; } /// - /// The for building a by-convention function parameter. + /// The for configuring this function parameter. /// new IConventionDbFunctionParameterBuilder Builder { get; } @@ -29,9 +29,9 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun ConfigurationSource GetConfigurationSource(); /// - /// Sets the store type of the parameter in the database. + /// Sets the store type of the parameter. /// - /// The store type of the parameter in the database. + /// The store type of the parameter. /// Indicates whether the configuration was specified using a data annotation. string SetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false); @@ -42,7 +42,7 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun ConfigurationSource? GetStoreTypeConfigurationSource(); /// - /// Sets the type mapping of the parameter in the database. + /// Sets the type mapping of the parameter. /// /// The type mapping of the parameter in the database. /// Indicates whether the configuration was specified using a data annotation. diff --git a/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs index df1ec93148e..379eb78b830 100644 --- a/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs @@ -8,7 +8,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata { /// - /// Represents a database function parameter in an . + /// Represents a parameter in. /// public interface IDbFunctionParameter : IAnnotatable { diff --git a/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs index 334aeaffcc1..05a5bb071b5 100644 --- a/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs @@ -7,7 +7,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata { /// - /// Represents a mutable database function parameter in an . + /// Represents a parameter. /// public interface IMutableDbFunctionParameter : IMutableAnnotatable, IDbFunctionParameter { @@ -17,7 +17,7 @@ public interface IMutableDbFunctionParameter : IMutableAnnotatable, IDbFunctionP new IMutableDbFunction Function { get; } /// - /// Gets or sets the store (database) type of this parameter. + /// Gets or sets the store type of this parameter. /// new string StoreType { get; [param: CanBeNull] set; } diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs index 081c59d4f87..63e385722d1 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs @@ -88,6 +88,8 @@ public DbFunction( [NotNull] IMutableModel model, ConfigurationSource configurationSource) { + Check.NotEmpty(name, nameof(name)); + if (returnType == null || returnType == typeof(void)) { @@ -106,9 +108,7 @@ public DbFunction( ReturnType = returnType; Model = model; _configurationSource = configurationSource; -#pragma warning disable EF1001 // Internal EF Core API usage. - Builder = new InternalDbFunctionBuilder(this, ((Model)model).Builder.ModelBuilder); -#pragma warning restore EF1001 // Internal EF Core API usage. + Builder = new InternalDbFunctionBuilder(this, ((IConventionModel)model).Builder); _parameters = parameters == null ? new List() : parameters diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs index bbd4a1d52af..d3a6bc3bf55 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs @@ -43,9 +43,7 @@ public DbFunctionParameter( Name = name; Function = function; ClrType = clrType; -#pragma warning disable EF1001 // Internal EF Core API usage. Builder = new InternalDbFunctionParameterBuilder(this, function.Builder.ModelBuilder); -#pragma warning restore EF1001 // Internal EF Core API usage. } /// diff --git a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs index a25cb5bf1e9..a04bf81ff29 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; @@ -20,9 +20,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// -#pragma warning disable EF1001 // Internal EF Core API usage. - public class InternalDbFunctionBuilder : InternalModelItemBuilder, IConventionDbFunctionBuilder -#pragma warning restore EF1001 // Internal EF Core API usage. + public class InternalDbFunctionBuilder : AnnotatableBuilder, IConventionDbFunctionBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -30,7 +28,7 @@ public class InternalDbFunctionBuilder : InternalModelItemBuilder, I /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public InternalDbFunctionBuilder([NotNull] DbFunction function, [NotNull] InternalModelBuilder modelBuilder) + public InternalDbFunctionBuilder([NotNull] DbFunction function, [NotNull] IConventionModelBuilder modelBuilder) : base(function, modelBuilder) { } diff --git a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs index c40d6f820e6..f239ac2ea2b 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs @@ -18,9 +18,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// and it is not designed to be directly constructed in your application code. /// /// -#pragma warning disable EF1001 // Internal EF Core API usage. - public class InternalDbFunctionParameterBuilder : InternalModelItemBuilder, IConventionDbFunctionParameterBuilder -#pragma warning restore EF1001 // Internal EF Core API usage. + public class InternalDbFunctionParameterBuilder : AnnotatableBuilder, IConventionDbFunctionParameterBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -29,7 +27,7 @@ public class InternalDbFunctionParameterBuilder : InternalModelItemBuilder [EntityFrameworkInternal] - public InternalDbFunctionParameterBuilder([NotNull] DbFunctionParameter parameter, [NotNull] InternalModelBuilder modelBuilder) + public InternalDbFunctionParameterBuilder([NotNull] DbFunctionParameter parameter, [NotNull] IConventionModelBuilder modelBuilder) : base(parameter, modelBuilder) { } diff --git a/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs b/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs index b02ec5096f2..c0165800bd6 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Linq; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Microsoft.EntityFrameworkCore.Metadata.Builders @@ -15,9 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// -#pragma warning disable EF1001 // Internal EF Core API usage. - public class InternalSequenceBuilder : InternalModelItemBuilder, IConventionSequenceBuilder -#pragma warning restore EF1001 // Internal EF Core API usage. + public class InternalSequenceBuilder : AnnotatableBuilder, IConventionSequenceBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -25,7 +24,7 @@ public class InternalSequenceBuilder : InternalModelItemBuilder, IConv /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public InternalSequenceBuilder([NotNull] Sequence sequence, [NotNull] InternalModelBuilder modelBuilder) + public InternalSequenceBuilder([NotNull] Sequence sequence, [NotNull] IConventionModelBuilder modelBuilder) : base(sequence, modelBuilder) { } diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs index 90d924ee565..95e0928272a 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs @@ -912,9 +912,7 @@ private static string GetDefiningNavigationName(IEntityType entityType) return entityType.DefiningNavigationName; } -#pragma warning disable EF1001 // Internal EF Core API usage. - var primaryKey = entityType.FindDeclaredPrimaryKey(); -#pragma warning restore EF1001 // Internal EF Core API usage. + var primaryKey = entityType.BaseType == null ? entityType.FindPrimaryKey() : null; if (primaryKey != null) { var definingForeignKey = entityType @@ -1842,9 +1840,8 @@ protected virtual void DiffData( var sourceValue = sourceEntry.GetCurrentValue(sourceProperty); var targetValue = entry.GetCurrentValue(targetProperty); - var comparer = targetProperty.GetValueComparer(fallback: false) - ?? sourceProperty.GetValueComparer(fallback: false) - ?? targetProperty.FindTypeMapping()?.Comparer ?? sourceProperty.FindTypeMapping()?.Comparer; + var comparer = targetProperty.GetValueComparer() + ?? sourceProperty.GetValueComparer(); var modelValuesChanged = sourceProperty.ClrType.UnwrapNullableType() == targetProperty.ClrType.UnwrapNullableType() diff --git a/src/EFCore/Infrastructure/AnnotatableBuilder.cs b/src/EFCore/Infrastructure/AnnotatableBuilder.cs new file mode 100644 index 00000000000..f09a005d4fc --- /dev/null +++ b/src/EFCore/Infrastructure/AnnotatableBuilder.cs @@ -0,0 +1,223 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Diagnostics; +using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Internal; + +namespace Microsoft.EntityFrameworkCore.Infrastructure +{ + /// + /// + /// A base type with a simple API surface for configuring a . + /// + /// + /// This type is typically used by database providers (and other extensions). It is generally + /// not used in application code. + /// + /// + [DebuggerDisplay("Builder {" + nameof(Metadata) + ",nq}")] + public abstract class AnnotatableBuilder : IConventionAnnotatableBuilder + where TMetadata : ConventionAnnotatable + where TModelBuilder : IConventionModelBuilder + { + /// + /// Creates a new instance of + /// + protected AnnotatableBuilder([NotNull] TMetadata metadata, [NotNull] TModelBuilder modelBuilder) + { + Metadata = metadata; + ModelBuilder = modelBuilder; + } + + /// + /// Gets the item being configured. + /// + public virtual TMetadata Metadata { get; } + + /// + /// Gets the model builder. + /// + public virtual TModelBuilder ModelBuilder { get; } + + /// + /// Sets the annotation with given key and value on this object using given configuration source. + /// Overwrites the existing annotation if an annotation with the specified name already exists. + /// + /// The key of the annotation to be set. + /// The value to be stored in the annotation. + /// The configuration source of the annotation to be set. + /// The same builder so that multiple calls can be chained. + public virtual AnnotatableBuilder HasAnnotation( + [NotNull] string name, [CanBeNull] object value, ConfigurationSource configurationSource) + => HasAnnotation(name, value, configurationSource, canOverrideSameSource: true); + + private AnnotatableBuilder HasAnnotation( + string name, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) + { + var existingAnnotation = Metadata.FindAnnotation(name); + if (existingAnnotation != null) + { + if (Equals(existingAnnotation.Value, value)) + { + existingAnnotation.UpdateConfigurationSource(configurationSource); + return this; + } + + if (!CanSetAnnotationValue(existingAnnotation, value, configurationSource, canOverrideSameSource)) + { + return null; + } + + Metadata.SetAnnotation(name, value, configurationSource); + + return this; + } + + Metadata.AddAnnotation(name, value, configurationSource); + + return this; + } + + /// + /// Sets the annotation with given key and value on this object using given configuration source. + /// Overwrites the existing annotation if an annotation with the specified name already exists. + /// Removes the annotation if null value is specified. + /// + /// The key of the annotation to be set. + /// The value to be stored in the annotation. + /// The configuration source of the annotation to be set. + /// The same builder so that multiple calls can be chained. + public virtual AnnotatableBuilder HasNonNullAnnotation( + [NotNull] string name, [CanBeNull] object value, ConfigurationSource configurationSource) + => value == null + ? RemoveAnnotation(name, configurationSource) + : HasAnnotation(name, value, configurationSource, canOverrideSameSource: true); + + /// + /// Returns a value indicating whether an annotation with the given name and value can be set from this configuration source. + /// + /// The name of the annotation to be added. + /// The value to be stored in the annotation. + /// The configuration source of the annotation to be set. + /// true if the annotation can be set, false otherwise. + public virtual bool CanSetAnnotation([NotNull] string name, [CanBeNull] object value, ConfigurationSource configurationSource) + { + var existingAnnotation = Metadata.FindAnnotation(name); + return existingAnnotation == null + || CanSetAnnotationValue(existingAnnotation, value, configurationSource, canOverrideSameSource: true); + } + + private static bool CanSetAnnotationValue( + ConventionAnnotation annotation, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) + { + if (Equals(annotation.Value, value)) + { + return true; + } + + var existingConfigurationSource = annotation.GetConfigurationSource(); + return configurationSource.Overrides(existingConfigurationSource) + && (configurationSource != existingConfigurationSource + || canOverrideSameSource); + } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual AnnotatableBuilder RemoveAnnotation([NotNull] string name, ConfigurationSource configurationSource) + { + if (!CanRemoveAnnotation(name, configurationSource)) + { + return null; + } + + Metadata.RemoveAnnotation(name); + return this; + } + + /// + /// Returns a value indicating whether an annotation with the given name can be removed using this configuration source. + /// + /// The name of the annotation to remove. + /// The configuration source of the annotation to be set. + /// true if the annotation can be removed, false otherwise. + public virtual bool CanRemoveAnnotation([NotNull] string name, ConfigurationSource configurationSource) + { + var existingAnnotation = Metadata.FindAnnotation(name); + return existingAnnotation == null + || configurationSource.Overrides(existingAnnotation.GetConfigurationSource()); + } + + /// + /// Copies all the explicitly configured annotations from the given object ovewriting any existing ones. + /// + /// The object to copy annotations from. + public virtual void MergeAnnotationsFrom([NotNull] TMetadata annotatable) + => MergeAnnotationsFrom(annotatable, ConfigurationSource.Explicit); + + /// + /// Copies all the configured annotations from the given object ovewriting any existing ones. + /// + /// The object to copy annotations from. + /// The minimum configuration source for an annoptation to be copied. + public virtual void MergeAnnotationsFrom([NotNull] TMetadata annotatable, ConfigurationSource minimalConfigurationSource) + { + foreach (var annotation in annotatable.GetAnnotations()) + { + var configurationSource = annotation.GetConfigurationSource(); + if (configurationSource.Overrides(minimalConfigurationSource)) + { + HasAnnotation( + annotation.Name, + annotation.Value, + configurationSource, + canOverrideSameSource: false); + } + } + } + + /// + IConventionModelBuilder IConventionAnnotatableBuilder.ModelBuilder + { + [DebuggerStepThrough] get => ModelBuilder; + } + + /// + IConventionAnnotatable IConventionAnnotatableBuilder.Metadata + { + [DebuggerStepThrough] get => Metadata; + } + + /// + [DebuggerStepThrough] + IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasAnnotation(string name, object value, bool fromDataAnnotation) + => HasAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + + /// + [DebuggerStepThrough] + IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasNonNullAnnotation( + string name, object value, bool fromDataAnnotation) + => HasNonNullAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + + /// + [DebuggerStepThrough] + bool IConventionAnnotatableBuilder.CanSetAnnotation(string name, object value, bool fromDataAnnotation) + => CanSetAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + + /// + [DebuggerStepThrough] + IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasNoAnnotation(string name, bool fromDataAnnotation) + => RemoveAnnotation(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + + /// + [DebuggerStepThrough] + bool IConventionAnnotatableBuilder.CanRemoveAnnotation(string name, bool fromDataAnnotation) + => CanRemoveAnnotation(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + } +} diff --git a/src/EFCore/Infrastructure/ConventionAnnotatable.cs b/src/EFCore/Infrastructure/ConventionAnnotatable.cs index 135ea7d817e..1057413a5df 100644 --- a/src/EFCore/Infrastructure/ConventionAnnotatable.cs +++ b/src/EFCore/Infrastructure/ConventionAnnotatable.cs @@ -25,12 +25,12 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure public abstract class ConventionAnnotatable : Annotatable, IConventionAnnotatable { /// - /// Gets all convention annotations on the current object. + /// Gets all annotations on the current object. /// public new virtual IEnumerable GetAnnotations() => base.GetAnnotations().Cast(); /// - /// Adds a convention annotation with given key and value to this object using given configuration source. + /// Adds a annotation with given key and value to this object using given configuration source. /// Throws if an annotation with the specified name already exists. /// /// The key of the annotation to be added. @@ -42,7 +42,7 @@ public virtual ConventionAnnotation AddAnnotation( => (ConventionAnnotation)base.AddAnnotation(name, CreateAnnotation(name, value, configurationSource)); /// - /// Sets the convention annotation with given key and value to this object using given configuration source. + /// Sets the annotation with given key and value on this object using given configuration source. /// Overwrites the existing annotation if an annotation with the specified name already exists. /// /// The key of the annotation to be added. @@ -77,7 +77,7 @@ protected override Annotation OnAnnotationSet(string name, Annotation annotation => (Annotation)OnAnnotationSet(name, (IConventionAnnotation)annotation, (IConventionAnnotation)oldAnnotation); /// - /// Runs the corresponding conventions when an annotation was set or removed. + /// Called when an annotation was set or removed. /// /// The key of the set annotation. /// The annotation set. diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs index f68ddde135a..0ff22f8a995 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs @@ -22,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// and it is not designed to be directly constructed in your application code. /// /// - public class CollectionNavigationBuilder : IInfrastructure + public class CollectionNavigationBuilder : IInfrastructure { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -56,7 +56,7 @@ public CollectionNavigationBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder Builder { get; private set; } + protected virtual InternalForeignKeyBuilder Builder { get; private set; } private IMutableSkipNavigation SkipNavigation { get; set; } @@ -105,7 +105,7 @@ public CollectionNavigationBuilder( /// not directly exposed in the public API surface. /// /// - InternalRelationshipBuilder IInfrastructure.Instance => Builder; + InternalForeignKeyBuilder IInfrastructure.Instance => Builder; /// /// @@ -136,7 +136,7 @@ public virtual ReferenceCollectionBuilder WithOne([CanBeNull] string navigationN /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder WithOneBuilder([CanBeNull] string navigationName) + protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] string navigationName) => WithOneBuilder(MemberIdentity.Create(navigationName)); /// @@ -146,11 +146,11 @@ protected virtual InternalRelationshipBuilder WithOneBuilder([CanBeNull] string /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder WithOneBuilder( + protected virtual InternalForeignKeyBuilder WithOneBuilder( [CanBeNull] MemberInfo navigationMemberInfo) => WithOneBuilder(MemberIdentity.Create(navigationMemberInfo)); - private InternalRelationshipBuilder WithOneBuilder(MemberIdentity reference) + private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) { if (SkipNavigation != null) { @@ -173,7 +173,7 @@ private InternalRelationshipBuilder WithOneBuilder(MemberIdentity reference) && foreignKey.GetDependentToPrincipalConfigurationSource() == ConfigurationSource.Explicit && foreignKey.DependentToPrincipal.Name != referenceName) { - InternalRelationshipBuilder.ThrowForConflictingNavigation(foreignKey, referenceName, newToPrincipal: true); + InternalForeignKeyBuilder.ThrowForConflictingNavigation(foreignKey, referenceName, newToPrincipal: true); } return reference.MemberInfo == null || CollectionMember == null @@ -236,7 +236,7 @@ protected virtual IMutableSkipNavigation WithLeftManyNavigation([NotNull] string var navigationMember = foreignKey.PrincipalToDependent.CreateMemberIdentity(); if (foreignKey.GetDependentToPrincipalConfigurationSource() == ConfigurationSource.Explicit) { - InternalRelationshipBuilder.ThrowForConflictingNavigation( + InternalForeignKeyBuilder.ThrowForConflictingNavigation( foreignKey, DeclaringEntityType, RelatedEntityType, navigationMember.Name, inverseName); } @@ -280,7 +280,7 @@ private IMutableSkipNavigation WithRightManyNavigation(MemberIdentity navigation var foreignKey = (ForeignKey)conflictingNavigation?.ForeignKey; if (conflictingNavigation?.GetConfigurationSource() == ConfigurationSource.Explicit) { - InternalRelationshipBuilder.ThrowForConflictingNavigation( + InternalForeignKeyBuilder.ThrowForConflictingNavigation( foreignKey, DeclaringEntityType, RelatedEntityType, inverseName, navigationName); } diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs index 6bde5d52d30..fa77e9f8017 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs @@ -401,7 +401,7 @@ public virtual EntityTypeBuilder OwnsOne( private OwnedNavigationBuilder OwnsOneBuilder(in TypeIdentity ownedType, string navigationName) { - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (Builder.Metadata.Model.ConventionDispatcher.DelayConventions()) { relationship = ownedType.Type == null @@ -548,7 +548,7 @@ public virtual EntityTypeBuilder OwnsMany( private OwnedNavigationBuilder OwnsManyBuilder(in TypeIdentity ownedType, string navigationName) { - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (Builder.Metadata.Model.ConventionDispatcher.DelayConventions()) { relationship = ownedType.Type == null @@ -817,7 +817,7 @@ private CollectionNavigationBuilder HasMany( { var skipNavigation = navigationName != null ? Builder.Metadata.FindSkipNavigation(navigationName) : null; - InternalRelationshipBuilder relationship = null; + InternalForeignKeyBuilder relationship = null; if (skipNavigation == null) { relationship = Builder diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs index 4573724e94b..dad7807dcf2 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs @@ -342,14 +342,14 @@ public virtual EntityTypeBuilder OwnsOne( private OwnedNavigationBuilder OwnsOneBuilder(MemberIdentity navigation) where TRelatedEntity : class { - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (var batch = Builder.Metadata.Model.ConventionDispatcher.DelayConventions()) { relationship = navigation.MemberInfo == null ? Builder.HasOwnership(typeof(TRelatedEntity), navigation.Name, ConfigurationSource.Explicit) : Builder.HasOwnership(typeof(TRelatedEntity), (PropertyInfo)navigation.MemberInfo, ConfigurationSource.Explicit); relationship.IsUnique(true, ConfigurationSource.Explicit); - relationship = (InternalRelationshipBuilder)batch.Run(relationship.Metadata).Builder; + relationship = (InternalForeignKeyBuilder)batch.Run(relationship.Metadata).Builder; } return new OwnedNavigationBuilder( @@ -488,14 +488,14 @@ public virtual EntityTypeBuilder OwnsMany( private OwnedNavigationBuilder OwnsManyBuilder(MemberIdentity navigation) where TRelatedEntity : class { - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (var batch = Builder.Metadata.Model.ConventionDispatcher.DelayConventions()) { relationship = navigation.MemberInfo == null ? Builder.HasOwnership(typeof(TRelatedEntity), navigation.Name, ConfigurationSource.Explicit) : Builder.HasOwnership(typeof(TRelatedEntity), (PropertyInfo)navigation.MemberInfo, ConfigurationSource.Explicit); relationship.IsUnique(false, ConfigurationSource.Explicit); - relationship = (InternalRelationshipBuilder)batch.Run(relationship.Metadata).Builder; + relationship = (InternalForeignKeyBuilder)batch.Run(relationship.Metadata).Builder; } return new OwnedNavigationBuilder( @@ -623,7 +623,7 @@ public virtual CollectionNavigationBuilder HasMany HasMany /// Base class used for configuring an invertible relationship. /// - public abstract class InvertibleRelationshipBuilderBase : IInfrastructure + public abstract class InvertibleRelationshipBuilderBase : IInfrastructure { private readonly IReadOnlyList _foreignKeyProperties; private readonly IReadOnlyList _principalKeyProperties; @@ -50,7 +50,7 @@ protected InvertibleRelationshipBuilderBase( /// [EntityFrameworkInternal] protected InvertibleRelationshipBuilderBase( - [NotNull] InternalRelationshipBuilder builder, + [NotNull] InternalForeignKeyBuilder builder, [CanBeNull] InvertibleRelationshipBuilderBase oldBuilder, bool inverted = false, bool foreignKeySet = false, @@ -113,12 +113,12 @@ protected InvertibleRelationshipBuilderBase( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder Builder { get; [param: NotNull] set; } + protected virtual InternalForeignKeyBuilder Builder { get; [param: NotNull] set; } /// /// Gets the internal builder being used to configure this relationship. /// - InternalRelationshipBuilder IInfrastructure.Instance => Builder; + InternalForeignKeyBuilder IInfrastructure.Instance => Builder; /// /// The foreign key that represents this relationship. diff --git a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs index 974cc8fc152..10c1fc1b222 100644 --- a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs @@ -17,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// public class OwnedNavigationBuilder : IInfrastructure { - private InternalRelationshipBuilder _builder; + private InternalForeignKeyBuilder _builder; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -29,7 +29,7 @@ public class OwnedNavigationBuilder : IInfrastructure public OwnedNavigationBuilder( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, - [NotNull] InternalRelationshipBuilder builder) + [NotNull] InternalForeignKeyBuilder builder) { PrincipalEntityType = principalEntityType; DependentEntityType = dependentEntityType; @@ -53,7 +53,7 @@ public OwnedNavigationBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder Builder + protected virtual InternalForeignKeyBuilder Builder { get { @@ -444,7 +444,7 @@ public virtual OwnedNavigationBuilder OwnsOne( private OwnedNavigationBuilder OwnsOneBuilder(in TypeIdentity ownedType, string navigationName) { - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (DependentEntityType.Model.ConventionDispatcher.DelayConventions()) { relationship = ownedType.Type == null @@ -597,7 +597,7 @@ public virtual OwnedNavigationBuilder OwnsMany( private OwnedNavigationBuilder OwnsManyBuilder(in TypeIdentity ownedType, string navigationName) { - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (DependentEntityType.Model.ConventionDispatcher.DelayConventions()) { relationship = ownedType.Type == null diff --git a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs index 34d8fd57a1f..a7e391e8e64 100644 --- a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs @@ -30,7 +30,7 @@ public class OwnedNavigationBuilder : OwnedNavigation public OwnedNavigationBuilder( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, - [NotNull] InternalRelationshipBuilder builder) + [NotNull] InternalForeignKeyBuilder builder) : base(principalEntityType, dependentEntityType, builder) { } @@ -343,7 +343,7 @@ private OwnedNavigationBuilder OwnsOneBui MemberIdentity navigation) where TNewDependentEntity : class { - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (var batch = DependentEntityType.Model.ConventionDispatcher.DelayConventions()) { relationship = navigation.MemberInfo == null @@ -351,7 +351,7 @@ private OwnedNavigationBuilder OwnsOneBui : DependentEntityType.Builder.HasOwnership( typeof(TNewDependentEntity), (PropertyInfo)navigation.MemberInfo, ConfigurationSource.Explicit); relationship.IsUnique(true, ConfigurationSource.Explicit); - relationship = (InternalRelationshipBuilder)batch.Run(relationship.Metadata).Builder; + relationship = (InternalForeignKeyBuilder)batch.Run(relationship.Metadata).Builder; } return new OwnedNavigationBuilder( @@ -496,7 +496,7 @@ public virtual OwnedNavigationBuilder OwnsMany OwnsManyBuilder(MemberIdentity navigation) where TNewRelatedEntity : class { - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (var batch = DependentEntityType.Model.ConventionDispatcher.DelayConventions()) { relationship = navigation.MemberInfo == null @@ -504,7 +504,7 @@ private OwnedNavigationBuilder OwnsManyBuil : DependentEntityType.Builder.HasOwnership( typeof(TNewRelatedEntity), (PropertyInfo)navigation.MemberInfo, ConfigurationSource.Explicit); relationship.IsUnique(false, ConfigurationSource.Explicit); - relationship = (InternalRelationshipBuilder)batch.Run(relationship.Metadata).Builder; + relationship = (InternalForeignKeyBuilder)batch.Run(relationship.Metadata).Builder; } return new OwnedNavigationBuilder( diff --git a/src/EFCore/Metadata/Builders/OwnershipBuilder.cs b/src/EFCore/Metadata/Builders/OwnershipBuilder.cs index 9591471a277..ebd592e1284 100644 --- a/src/EFCore/Metadata/Builders/OwnershipBuilder.cs +++ b/src/EFCore/Metadata/Builders/OwnershipBuilder.cs @@ -39,7 +39,7 @@ public OwnershipBuilder( /// [EntityFrameworkInternal] protected OwnershipBuilder( - [NotNull] InternalRelationshipBuilder builder, + [NotNull] InternalForeignKeyBuilder builder, [CanBeNull] OwnershipBuilder oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, diff --git a/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs b/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs index 90d10865fce..57746ac5635 100644 --- a/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs +++ b/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs @@ -43,7 +43,7 @@ public OwnershipBuilder( /// [EntityFrameworkInternal] protected OwnershipBuilder( - [NotNull] InternalRelationshipBuilder builder, + [NotNull] InternalForeignKeyBuilder builder, [CanBeNull] OwnershipBuilder oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, diff --git a/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder.cs b/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder.cs index 2cdab341ef6..62e61a324f0 100644 --- a/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder.cs +++ b/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder.cs @@ -45,7 +45,7 @@ public ReferenceCollectionBuilder( /// [EntityFrameworkInternal] protected ReferenceCollectionBuilder( - [NotNull] InternalRelationshipBuilder builder, + [NotNull] InternalForeignKeyBuilder builder, [CanBeNull] ReferenceCollectionBuilder oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, @@ -107,7 +107,7 @@ public virtual ReferenceCollectionBuilder HasForeignKey([NotNull] params string[ /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder HasForeignKeyBuilder([NotNull] IReadOnlyList foreignKeyPropertyNames) + protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder([NotNull] IReadOnlyList foreignKeyPropertyNames) => Builder.HasForeignKey(foreignKeyPropertyNames, (EntityType)DependentEntityType, ConfigurationSource.Explicit); /// @@ -117,7 +117,7 @@ protected virtual InternalRelationshipBuilder HasForeignKeyBuilder([NotNull] IRe /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder HasForeignKeyBuilder([NotNull] IReadOnlyList foreignKeyProperties) + protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder([NotNull] IReadOnlyList foreignKeyProperties) => Builder.HasForeignKey(foreignKeyProperties, (EntityType)DependentEntityType, ConfigurationSource.Explicit); /// @@ -141,7 +141,7 @@ public virtual ReferenceCollectionBuilder HasPrincipalKey([NotNull] params strin /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder HasPrincipalKeyBuilder([NotNull] IReadOnlyList keyPropertyNames) + protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder([NotNull] IReadOnlyList keyPropertyNames) => Builder.HasPrincipalKey(keyPropertyNames, ConfigurationSource.Explicit); /// @@ -151,7 +151,7 @@ protected virtual InternalRelationshipBuilder HasPrincipalKeyBuilder([NotNull] I /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder HasPrincipalKeyBuilder([NotNull] IReadOnlyList keyProperties) + protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder([NotNull] IReadOnlyList keyProperties) => Builder.HasPrincipalKey(keyProperties, ConfigurationSource.Explicit); /// diff --git a/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder`.cs b/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder`.cs index 4fd6d44bc94..e4138e1365a 100644 --- a/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder`.cs +++ b/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder`.cs @@ -49,7 +49,7 @@ public ReferenceCollectionBuilder( /// [EntityFrameworkInternal] protected ReferenceCollectionBuilder( - [NotNull] InternalRelationshipBuilder builder, + [NotNull] InternalForeignKeyBuilder builder, [CanBeNull] ReferenceCollectionBuilder oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, diff --git a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs index 7d6bfc4cd92..e308a0bb501 100644 --- a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs @@ -24,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// and it is not designed to be directly constructed in your application code. /// /// - public class ReferenceNavigationBuilder : IInfrastructure + public class ReferenceNavigationBuilder : IInfrastructure { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -78,7 +78,7 @@ public ReferenceNavigationBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder Builder { [DebuggerStepThrough] get; } + protected virtual InternalForeignKeyBuilder Builder { [DebuggerStepThrough] get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -119,7 +119,7 @@ public ReferenceNavigationBuilder( /// /// Gets the internal builder being used to configure the relationship. /// - InternalRelationshipBuilder IInfrastructure.Instance => Builder; + InternalForeignKeyBuilder IInfrastructure.Instance => Builder; /// /// @@ -151,7 +151,7 @@ public virtual ReferenceCollectionBuilder WithMany([CanBeNull] string collection /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder WithManyBuilder([CanBeNull] string navigationName) + protected virtual InternalForeignKeyBuilder WithManyBuilder([CanBeNull] string navigationName) => WithManyBuilder(MemberIdentity.Create(navigationName)); /// @@ -161,10 +161,10 @@ protected virtual InternalRelationshipBuilder WithManyBuilder([CanBeNull] string /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder WithManyBuilder([CanBeNull] MemberInfo navigationMemberInfo) + protected virtual InternalForeignKeyBuilder WithManyBuilder([CanBeNull] MemberInfo navigationMemberInfo) => WithManyBuilder(MemberIdentity.Create(navigationMemberInfo)); - private InternalRelationshipBuilder WithManyBuilder(MemberIdentity collection) + private InternalForeignKeyBuilder WithManyBuilder(MemberIdentity collection) { var builder = Builder.HasEntityTypes( (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit); @@ -174,7 +174,7 @@ private InternalRelationshipBuilder WithManyBuilder(MemberIdentity collection) && builder.Metadata.GetPrincipalToDependentConfigurationSource() == ConfigurationSource.Explicit && collectionName != null) { - InternalRelationshipBuilder.ThrowForConflictingNavigation(builder.Metadata, collectionName, false); + InternalForeignKeyBuilder.ThrowForConflictingNavigation(builder.Metadata, collectionName, false); } builder = builder.IsUnique(false, ConfigurationSource.Explicit); @@ -184,7 +184,7 @@ private InternalRelationshipBuilder WithManyBuilder(MemberIdentity collection) && foreignKey.GetPrincipalToDependentConfigurationSource() == ConfigurationSource.Explicit && foreignKey.PrincipalToDependent.Name != collectionName) { - InternalRelationshipBuilder.ThrowForConflictingNavigation(foreignKey, collectionName, false); + InternalForeignKeyBuilder.ThrowForConflictingNavigation(foreignKey, collectionName, false); } return collection.MemberInfo == null || ReferenceMember == null @@ -224,7 +224,7 @@ public virtual ReferenceReferenceBuilder WithOne([CanBeNull] string reference = /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder WithOneBuilder([CanBeNull] string navigationName) + protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] string navigationName) => WithOneBuilder(MemberIdentity.Create(navigationName)); /// @@ -234,11 +234,11 @@ protected virtual InternalRelationshipBuilder WithOneBuilder([CanBeNull] string /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder WithOneBuilder( + protected virtual InternalForeignKeyBuilder WithOneBuilder( [CanBeNull] MemberInfo navigationMemberInfo) => WithOneBuilder(MemberIdentity.Create(navigationMemberInfo)); - private InternalRelationshipBuilder WithOneBuilder(MemberIdentity reference) + private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) { var referenceName = reference.Name; if (!Builder.Metadata.IsUnique @@ -246,7 +246,7 @@ private InternalRelationshipBuilder WithOneBuilder(MemberIdentity reference) && Builder.Metadata.GetPrincipalToDependentConfigurationSource() == ConfigurationSource.Explicit && referenceName != null) { - InternalRelationshipBuilder.ThrowForConflictingNavigation(Builder.Metadata, referenceName, false); + InternalForeignKeyBuilder.ThrowForConflictingNavigation(Builder.Metadata, referenceName, false); } using var batch = Builder.Metadata.DeclaringEntityType.Model.ConventionDispatcher.DelayConventions(); @@ -279,7 +279,7 @@ private InternalRelationshipBuilder WithOneBuilder(MemberIdentity reference) && foreignKey.GetPrincipalToDependentConfigurationSource() == ConfigurationSource.Explicit && foreignKey.PrincipalToDependent.Name != referenceName))) { - InternalRelationshipBuilder.ThrowForConflictingNavigation(foreignKey, referenceName, pointsToPrincipal); + InternalForeignKeyBuilder.ThrowForConflictingNavigation(foreignKey, referenceName, pointsToPrincipal); } var referenceProperty = reference.MemberInfo; diff --git a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs index 80207fe375f..2c3bed65358 100644 --- a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs +++ b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs @@ -44,7 +44,7 @@ public ReferenceReferenceBuilder( /// [EntityFrameworkInternal] protected ReferenceReferenceBuilder( - [NotNull] InternalRelationshipBuilder builder, + [NotNull] InternalForeignKeyBuilder builder, [CanBeNull] ReferenceReferenceBuilder oldBuilder, bool inverted = false, bool foreignKeySet = false, @@ -154,7 +154,7 @@ public virtual ReferenceReferenceBuilder HasForeignKey( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder HasForeignKeyBuilder( + protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder( [CanBeNull] EntityType dependentEntityType, [NotNull] string dependentEntityTypeName, [NotNull] IReadOnlyList foreignKeyPropertyNames) @@ -169,7 +169,7 @@ protected virtual InternalRelationshipBuilder HasForeignKeyBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder HasForeignKeyBuilder( + protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder( [NotNull] EntityType dependentEntityType, [NotNull] string dependentEntityTypeName, [NotNull] IReadOnlyList foreignKeyProperties) @@ -177,10 +177,10 @@ protected virtual InternalRelationshipBuilder HasForeignKeyBuilder( dependentEntityType, dependentEntityTypeName, (b, d) => b.HasForeignKey(foreignKeyProperties, d, ConfigurationSource.Explicit)); - private InternalRelationshipBuilder HasForeignKeyBuilder( + private InternalForeignKeyBuilder HasForeignKeyBuilder( EntityType dependentEntityType, string dependentEntityTypeName, - Func hasForeignKey) + Func hasForeignKey) { if (dependentEntityType == null) { @@ -264,7 +264,7 @@ public virtual ReferenceReferenceBuilder HasPrincipalKey( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder HasPrincipalKeyBuilder( + protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder( [CanBeNull] EntityType principalEntityType, [NotNull] string principalEntityTypeName, [NotNull] IReadOnlyList foreignKeyPropertyNames) @@ -279,7 +279,7 @@ protected virtual InternalRelationshipBuilder HasPrincipalKeyBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder HasPrincipalKeyBuilder( + protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder( [NotNull] EntityType principalEntityType, [NotNull] string principalEntityTypeName, [NotNull] IReadOnlyList foreignKeyProperties) @@ -287,10 +287,10 @@ protected virtual InternalRelationshipBuilder HasPrincipalKeyBuilder( principalEntityType, principalEntityTypeName, b => b.HasPrincipalKey(foreignKeyProperties, ConfigurationSource.Explicit)); - private InternalRelationshipBuilder HasPrincipalKeyBuilder( + private InternalForeignKeyBuilder HasPrincipalKeyBuilder( EntityType principalEntityType, string principalEntityTypeName, - Func hasPrincipalKey) + Func hasPrincipalKey) { if (principalEntityType == null) { diff --git a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs index f428782bc38..24eb472e472 100644 --- a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs +++ b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs @@ -43,7 +43,7 @@ public ReferenceReferenceBuilder( /// [EntityFrameworkInternal] protected ReferenceReferenceBuilder( - [NotNull] InternalRelationshipBuilder builder, + [NotNull] InternalForeignKeyBuilder builder, [CanBeNull] ReferenceReferenceBuilder oldBuilder, bool inverted = false, bool foreignKeySet = false, diff --git a/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs b/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs index 1bf65c3af35..333c0aa97f8 100644 --- a/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs +++ b/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// /// Base class used for configuring a relationship. /// - public abstract class RelationshipBuilderBase : IInfrastructure + public abstract class RelationshipBuilderBase : IInfrastructure { private readonly IReadOnlyList _foreignKeyProperties; private readonly IReadOnlyList _principalKeyProperties; @@ -44,7 +44,7 @@ protected RelationshipBuilderBase( /// [EntityFrameworkInternal] protected RelationshipBuilderBase( - [NotNull] InternalRelationshipBuilder builder, + [NotNull] InternalForeignKeyBuilder builder, [CanBeNull] RelationshipBuilderBase oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, @@ -97,7 +97,7 @@ protected RelationshipBuilderBase( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalRelationshipBuilder Builder { get; [param: NotNull] set; } + protected virtual InternalForeignKeyBuilder Builder { get; [param: NotNull] set; } /// /// The foreign key that represents this relationship. @@ -107,7 +107,7 @@ protected RelationshipBuilderBase( /// /// Gets the internal builder being used to configure this relationship. /// - InternalRelationshipBuilder IInfrastructure.Instance => Builder; + InternalForeignKeyBuilder IInfrastructure.Instance => Builder; #region Hidden System.Object members diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionBatchExtensions.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionBatchExtensions.cs index b367bd93473..469de08086d 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionBatchExtensions.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionBatchExtensions.cs @@ -22,8 +22,8 @@ public static class ConventionBatchExtensions /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - public static InternalRelationshipBuilder Run( - [NotNull] this IConventionBatch batch, [NotNull] InternalRelationshipBuilder relationshipBuilder) - => (InternalRelationshipBuilder)batch.Run(relationshipBuilder.Metadata)?.Builder; + public static InternalForeignKeyBuilder Run( + [NotNull] this IConventionBatch batch, [NotNull] InternalForeignKeyBuilder relationshipBuilder) + => (InternalForeignKeyBuilder)batch.Run(relationshipBuilder.Metadata)?.Builder; } } diff --git a/src/EFCore/Metadata/Internal/ForeignKey.cs b/src/EFCore/Metadata/Internal/ForeignKey.cs index 72fd7cf6ec3..77c205cb2e2 100644 --- a/src/EFCore/Metadata/Internal/ForeignKey.cs +++ b/src/EFCore/Metadata/Internal/ForeignKey.cs @@ -75,7 +75,7 @@ public ForeignKey( principalEntityType.DisplayName())); } - Builder = new InternalRelationshipBuilder(this, dependentEntityType.Model.Builder); + Builder = new InternalForeignKeyBuilder(this, dependentEntityType.Model.Builder); } /// @@ -116,7 +116,7 @@ public ForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder Builder + public virtual InternalForeignKeyBuilder Builder { get; diff --git a/src/EFCore/Metadata/Internal/InternalAnnotatableBuilder.cs b/src/EFCore/Metadata/Internal/InternalAnnotatableBuilder.cs deleted file mode 100644 index 6dfd4a8aa38..00000000000 --- a/src/EFCore/Metadata/Internal/InternalAnnotatableBuilder.cs +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Diagnostics; -using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace Microsoft.EntityFrameworkCore.Metadata.Internal -{ - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - [DebuggerDisplay("{" + nameof(Metadata) + ",nq}")] - public abstract class InternalAnnotatableBuilder : IConventionAnnotatableBuilder - { - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - protected InternalAnnotatableBuilder([NotNull] ConventionAnnotatable metadata) - { - Metadata = metadata; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual ConventionAnnotatable Metadata { [DebuggerStepThrough] get; } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public abstract InternalModelBuilder ModelBuilder { [DebuggerStepThrough] get; } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual InternalAnnotatableBuilder HasAnnotation( - [NotNull] string name, [CanBeNull] object value, ConfigurationSource configurationSource) - => HasAnnotation(name, value, configurationSource, canOverrideSameSource: true); - - private InternalAnnotatableBuilder HasAnnotation( - string name, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) - { - var existingAnnotation = Metadata.FindAnnotation(name); - if (existingAnnotation != null) - { - if (Equals(existingAnnotation.Value, value)) - { - existingAnnotation.UpdateConfigurationSource(configurationSource); - return this; - } - - if (!CanSetAnnotationValue(existingAnnotation, value, configurationSource, canOverrideSameSource)) - { - return null; - } - - Metadata.SetAnnotation(name, value, configurationSource); - - return this; - } - - Metadata.AddAnnotation(name, value, configurationSource); - - return this; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual InternalAnnotatableBuilder SetOrRemoveAnnotation( - [NotNull] string name, [CanBeNull] object value, ConfigurationSource configurationSource) - => value == null - ? RemoveAnnotation(name, configurationSource) - : HasAnnotation(name, value, configurationSource, canOverrideSameSource: true); - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual bool CanSetAnnotation([NotNull] string name, [CanBeNull] object value, ConfigurationSource configurationSource) - { - var existingAnnotation = Metadata.FindAnnotation(name); - return existingAnnotation == null - || CanSetAnnotationValue(existingAnnotation, value, configurationSource, canOverrideSameSource: true); - } - - private static bool CanSetAnnotationValue( - ConventionAnnotation annotation, object value, ConfigurationSource configurationSource, bool canOverrideSameSource) - { - if (Equals(annotation.Value, value)) - { - return true; - } - - var existingConfigurationSource = annotation.GetConfigurationSource(); - return configurationSource.Overrides(existingConfigurationSource) - && (configurationSource != existingConfigurationSource - || canOverrideSameSource); - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual InternalAnnotatableBuilder RemoveAnnotation([NotNull] string name, ConfigurationSource configurationSource) - { - if (!CanRemoveAnnotation(name, configurationSource)) - { - return null; - } - - Metadata.RemoveAnnotation(name); - return this; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual bool CanRemoveAnnotation([NotNull] string name, ConfigurationSource configurationSource) - { - var existingAnnotation = Metadata.FindAnnotation(name); - return existingAnnotation == null - || configurationSource.Overrides(existingAnnotation.GetConfigurationSource()); - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual void MergeAnnotationsFrom([NotNull] IConventionAnnotatable annotatable) - => MergeAnnotationsFrom(annotatable, ConfigurationSource.Explicit); - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual void MergeAnnotationsFrom( - [NotNull] IConventionAnnotatable annotatable, - ConfigurationSource minimalConfigurationSource) - { - foreach (var annotation in annotatable.GetAnnotations()) - { - var configurationSource = annotation.GetConfigurationSource(); - if (configurationSource.Overrides(minimalConfigurationSource)) - { - HasAnnotation( - annotation.Name, - annotation.Value, - configurationSource, - canOverrideSameSource: false); - } - } - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - IConventionModelBuilder IConventionAnnotatableBuilder.ModelBuilder => ModelBuilder; - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - IConventionAnnotatable IConventionAnnotatableBuilder.Metadata => Metadata; - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasAnnotation(string name, object value, bool fromDataAnnotation) - => HasAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasNonNullAnnotation( - string name, object value, bool fromDataAnnotation) - => SetOrRemoveAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - bool IConventionAnnotatableBuilder.CanSetAnnotation(string name, object value, bool fromDataAnnotation) - => CanSetAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasNoAnnotation(string name, bool fromDataAnnotation) - => RemoveAnnotation(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - bool IConventionAnnotatableBuilder.CanRemoveAnnotation(string name, bool fromDataAnnotation) - => CanRemoveAnnotation(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); - } -} diff --git a/src/EFCore/Metadata/Internal/InternalAnnotatableBuilder`.cs b/src/EFCore/Metadata/Internal/InternalAnnotatableBuilder`.cs deleted file mode 100644 index 8425feb39ea..00000000000 --- a/src/EFCore/Metadata/Internal/InternalAnnotatableBuilder`.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Diagnostics; -using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Infrastructure; - -namespace Microsoft.EntityFrameworkCore.Metadata.Internal -{ - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public abstract class InternalAnnotatableBuilder : InternalAnnotatableBuilder - where TMetadata : ConventionAnnotatable - { - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - protected InternalAnnotatableBuilder([NotNull] TMetadata metadata) - : base(metadata) - { - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public new virtual TMetadata Metadata - { - [DebuggerStepThrough] get => (TMetadata)base.Metadata; - } - } -} diff --git a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs index a82e63b3b1f..c87fce1f70b 100644 --- a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs @@ -24,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class InternalEntityTypeBuilder : InternalModelItemBuilder, IConventionEntityTypeBuilder + public class InternalEntityTypeBuilder : AnnotatableBuilder, IConventionEntityTypeBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -2297,7 +2297,7 @@ private static InternalIndexBuilder DetachIndex(Index indexToDetach) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] string principalEntityTypeName, [NotNull] IReadOnlyList propertyNames, ConfigurationSource configurationSource) @@ -2323,7 +2323,7 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] string principalEntityTypeName, [NotNull] IReadOnlyList propertyNames, [NotNull] Key principalKey, @@ -2348,7 +2348,7 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] Type principalClrType, [NotNull] IReadOnlyList clrMembers, ConfigurationSource configurationSource) @@ -2372,7 +2372,7 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] Type principalClrType, [NotNull] IReadOnlyList clrMembers, [NotNull] Key principalKey, @@ -2397,7 +2397,7 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] EntityType principalEntityType, [NotNull] IReadOnlyList dependentProperties, ConfigurationSource configurationSource) @@ -2413,7 +2413,7 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] EntityType principalEntityType, [NotNull] IReadOnlyList dependentProperties, [CanBeNull] Key principalKey, @@ -2424,7 +2424,7 @@ public virtual InternalRelationshipBuilder HasRelationship( principalKey, configurationSource); - private InternalRelationshipBuilder HasForeignKey( + private InternalForeignKeyBuilder HasForeignKey( EntityType principalEntityType, IReadOnlyList dependentProperties, Key principalKey, @@ -2455,7 +2455,7 @@ private InternalRelationshipBuilder HasForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] EntityType targetEntityType, [CanBeNull] string navigationName, ConfigurationSource configurationSource, @@ -2473,7 +2473,7 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] EntityType targetEntityType, [CanBeNull] MemberInfo navigationProperty, ConfigurationSource configurationSource, @@ -2491,7 +2491,7 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] EntityType targetEntityType, [CanBeNull] string navigationToTargetName, [CanBeNull] string inverseNavigationName, @@ -2510,7 +2510,7 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] EntityType targetEntityType, [CanBeNull] MemberInfo navigationToTarget, [CanBeNull] MemberInfo inverseNavigation, @@ -2523,7 +2523,7 @@ public virtual InternalRelationshipBuilder HasRelationship( setTargetAsPrincipal ? true : (bool?)null, configurationSource); - private InternalRelationshipBuilder HasRelationship( + private InternalForeignKeyBuilder HasRelationship( EntityType targetEntityType, MemberIdentity? navigationToTarget, MemberIdentity? inverseNavigation, @@ -2550,7 +2550,7 @@ private InternalRelationshipBuilder HasRelationship( Metadata, null, navigationToTarget, !targetIsPrincipal, configurationSource, required); } - var existingRelationship = InternalRelationshipBuilder.FindCurrentRelationshipBuilder( + var existingRelationship = InternalForeignKeyBuilder.FindCurrentRelationshipBuilder( targetEntityType, Metadata, navigationToTarget, @@ -2629,7 +2629,7 @@ private InternalRelationshipBuilder HasRelationship( } else { - existingRelationship = InternalRelationshipBuilder.FindCurrentRelationshipBuilder( + existingRelationship = InternalForeignKeyBuilder.FindCurrentRelationshipBuilder( Metadata, targetEntityType, inverseNavigation, @@ -2673,8 +2673,8 @@ private InternalRelationshipBuilder HasRelationship( } } - InternalRelationshipBuilder relationship; - InternalRelationshipBuilder newRelationship = null; + InternalForeignKeyBuilder relationship; + InternalForeignKeyBuilder newRelationship = null; using (var batcher = Metadata.Model.ConventionDispatcher.DelayConventions()) { if (existingRelationship != null) @@ -2795,7 +2795,7 @@ private InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] EntityType principalEntityType, ConfigurationSource configurationSource) => HasRelationshipInternal(principalEntityType, principalKey: null, configurationSource: configurationSource); @@ -2806,19 +2806,19 @@ public virtual InternalRelationshipBuilder HasRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasRelationship( + public virtual InternalForeignKeyBuilder HasRelationship( [NotNull] EntityType principalEntityType, [NotNull] Key principalKey, ConfigurationSource configurationSource) => HasRelationshipInternal(principalEntityType, principalKey, configurationSource); - private InternalRelationshipBuilder HasRelationshipInternal( + private InternalForeignKeyBuilder HasRelationshipInternal( EntityType targetEntityType, Key principalKey, ConfigurationSource configurationSource) { - InternalRelationshipBuilder relationship; - InternalRelationshipBuilder newRelationship; + InternalForeignKeyBuilder relationship; + InternalForeignKeyBuilder newRelationship; using (var batch = Metadata.Model.ConventionDispatcher.DelayConventions()) { relationship = CreateForeignKey( @@ -2858,7 +2858,7 @@ private InternalRelationshipBuilder HasRelationshipInternal( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasOwnership( + public virtual InternalForeignKeyBuilder HasOwnership( [NotNull] string targetEntityTypeName, [NotNull] string navigationName, ConfigurationSource configurationSource) @@ -2872,7 +2872,7 @@ public virtual InternalRelationshipBuilder HasOwnership( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasOwnership( + public virtual InternalForeignKeyBuilder HasOwnership( [NotNull] Type targetEntityType, [NotNull] string navigationName, ConfigurationSource configurationSource) @@ -2886,7 +2886,7 @@ public virtual InternalRelationshipBuilder HasOwnership( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasOwnership( + public virtual InternalForeignKeyBuilder HasOwnership( [NotNull] Type targetEntityType, [NotNull] MemberInfo navigationProperty, ConfigurationSource configurationSource) @@ -2900,7 +2900,7 @@ public virtual InternalRelationshipBuilder HasOwnership( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasOwnership( + public virtual InternalForeignKeyBuilder HasOwnership( [NotNull] Type targetEntityType, [NotNull] string navigationPropertyName, [CanBeNull] string inversePropertyName, @@ -2917,7 +2917,7 @@ public virtual InternalRelationshipBuilder HasOwnership( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasOwnership( + public virtual InternalForeignKeyBuilder HasOwnership( [NotNull] Type targetEntityType, [NotNull] MemberInfo navigationProperty, [CanBeNull] MemberInfo inverseProperty, @@ -2928,14 +2928,14 @@ public virtual InternalRelationshipBuilder HasOwnership( MemberIdentity.Create(inverseProperty), configurationSource); - private InternalRelationshipBuilder HasOwnership( + private InternalForeignKeyBuilder HasOwnership( in TypeIdentity targetEntityType, MemberIdentity navigation, MemberIdentity? inverse, ConfigurationSource configurationSource) { InternalEntityTypeBuilder ownedEntityType; - InternalRelationshipBuilder relationship; + InternalForeignKeyBuilder relationship; using (var batch = Metadata.Model.ConventionDispatcher.DelayConventions()) { var existingNavigation = Metadata.FindNavigation(navigation.Name); @@ -3241,7 +3241,7 @@ public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder CreateForeignKey( + public virtual InternalForeignKeyBuilder CreateForeignKey( [NotNull] InternalEntityTypeBuilder principalEntityTypeBuilder, [CanBeNull] IReadOnlyList dependentProperties, [CanBeNull] Key principalKey, @@ -3259,7 +3259,7 @@ public virtual InternalRelationshipBuilder CreateForeignKey( foreignKey.SetIsRequired(required.Value, configurationSource); } - return (InternalRelationshipBuilder)batch.Run(foreignKey)?.Builder; + return (InternalForeignKeyBuilder)batch.Run(foreignKey)?.Builder; } /// @@ -3268,7 +3268,7 @@ public virtual InternalRelationshipBuilder CreateForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder UpdateForeignKey( + public virtual InternalForeignKeyBuilder UpdateForeignKey( [NotNull] ForeignKey foreignKey, [CanBeNull] IReadOnlyList dependentProperties, [CanBeNull] Key principalKey, @@ -3281,7 +3281,7 @@ public virtual InternalRelationshipBuilder UpdateForeignKey( foreignKey, foreignKey.PrincipalEntityType.Builder, dependentProperties, principalKey, navigationToPrincipalName, isRequired, configurationSource); - return (InternalRelationshipBuilder)batch.Run(foreignKey)?.Builder; + return (InternalForeignKeyBuilder)batch.Run(foreignKey)?.Builder; } private ForeignKey SetOrAddForeignKey( diff --git a/src/EFCore/Metadata/Internal/InternalRelationshipBuilder.cs b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs similarity index 97% rename from src/EFCore/Metadata/Internal/InternalRelationshipBuilder.cs rename to src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs index d65fc29e490..f36f0118680 100644 --- a/src/EFCore/Metadata/Internal/InternalRelationshipBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs @@ -8,6 +8,7 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; @@ -21,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class InternalRelationshipBuilder : InternalModelItemBuilder, IConventionForeignKeyBuilder + public class InternalForeignKeyBuilder : AnnotatableBuilder, IConventionForeignKeyBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -29,7 +30,7 @@ public class InternalRelationshipBuilder : InternalModelItemBuilder, /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public InternalRelationshipBuilder( + public InternalForeignKeyBuilder( [NotNull] ForeignKey foreignKey, [NotNull] InternalModelBuilder modelBuilder) : base(foreignKey, modelBuilder) @@ -42,7 +43,7 @@ public InternalRelationshipBuilder( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasNavigation( + public virtual InternalForeignKeyBuilder HasNavigation( [CanBeNull] string name, bool pointsToPrincipal, ConfigurationSource configurationSource) @@ -62,7 +63,7 @@ public virtual InternalRelationshipBuilder HasNavigation( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasNavigation( + public virtual InternalForeignKeyBuilder HasNavigation( [CanBeNull] MemberInfo property, bool pointsToPrincipal, ConfigurationSource configurationSource) @@ -82,7 +83,7 @@ public virtual InternalRelationshipBuilder HasNavigation( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasNavigations( + public virtual InternalForeignKeyBuilder HasNavigations( [CanBeNull] string navigationToPrincipalName, [CanBeNull] string navigationToDependentName, ConfigurationSource configurationSource) @@ -97,7 +98,7 @@ public virtual InternalRelationshipBuilder HasNavigations( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasNavigations( + public virtual InternalForeignKeyBuilder HasNavigations( [CanBeNull] MemberInfo navigationToPrincipal, [CanBeNull] MemberInfo navigationToDependent, ConfigurationSource configurationSource) @@ -112,7 +113,7 @@ public virtual InternalRelationshipBuilder HasNavigations( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasNavigations( + public virtual InternalForeignKeyBuilder HasNavigations( MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, ConfigurationSource configurationSource) @@ -129,7 +130,7 @@ public virtual InternalRelationshipBuilder HasNavigations( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasNavigations( + public virtual InternalForeignKeyBuilder HasNavigations( [CanBeNull] string navigationToPrincipalName, [CanBeNull] string navigationToDependentName, [NotNull] EntityType principalEntityType, @@ -148,7 +149,7 @@ public virtual InternalRelationshipBuilder HasNavigations( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasNavigations( + public virtual InternalForeignKeyBuilder HasNavigations( [CanBeNull] MemberInfo navigationToPrincipal, [CanBeNull] MemberInfo navigationToDependent, [NotNull] EntityType principalEntityType, @@ -161,7 +162,7 @@ public virtual InternalRelationshipBuilder HasNavigations( dependentEntityType, configurationSource); - private InternalRelationshipBuilder HasNavigations( + private InternalForeignKeyBuilder HasNavigations( MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, EntityType principalEntityType, @@ -360,7 +361,7 @@ private InternalRelationshipBuilder HasNavigations( } } - InternalRelationshipBuilder builder; + InternalForeignKeyBuilder builder; if (shouldInvert == true || conflictingNavigationsFound || changeRelatedTypes) @@ -927,7 +928,7 @@ private static bool IsCompatible( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasField( + public virtual InternalForeignKeyBuilder HasField( [CanBeNull] string fieldName, bool pointsToPrincipal, ConfigurationSource configurationSource) { var navigation = pointsToPrincipal ? Metadata.DependentToPrincipal : Metadata.PrincipalToDependent; @@ -989,7 +990,7 @@ public virtual bool CanSetField([CanBeNull] string fieldName, bool pointsToPrinc /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasField( + public virtual InternalForeignKeyBuilder HasField( [CanBeNull] FieldInfo fieldInfo, bool pointsToPrincipal, ConfigurationSource configurationSource) { var navigation = pointsToPrincipal ? Metadata.DependentToPrincipal : Metadata.PrincipalToDependent; @@ -1035,7 +1036,7 @@ public virtual bool CanSetField([CanBeNull] FieldInfo fieldInfo, bool pointsToPr /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder UsePropertyAccessMode( + public virtual InternalForeignKeyBuilder UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool pointsToPrincipal, ConfigurationSource configurationSource) { var navigation = pointsToPrincipal ? Metadata.DependentToPrincipal : Metadata.PrincipalToDependent; @@ -1078,7 +1079,7 @@ public virtual bool CanSetPropertyAccessMode( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder IsEagerLoaded( + public virtual InternalForeignKeyBuilder IsEagerLoaded( bool? eagerLoaded, bool pointsToPrincipal, ConfigurationSource configurationSource) @@ -1125,7 +1126,7 @@ public virtual bool CanSetIsEagerLoaded( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder IsRequired(bool? required, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder IsRequired(bool? required, ConfigurationSource configurationSource) { if (!CanSetIsRequired(required, configurationSource)) { @@ -1153,7 +1154,7 @@ public virtual bool CanSetIsRequired(bool? required, ConfigurationSource? config /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder IsOwnership(bool? ownership, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder IsOwnership(bool? ownership, ConfigurationSource configurationSource) { if (Metadata.IsOwnership == ownership) { @@ -1312,7 +1313,7 @@ public virtual bool CanSetIsOwnership(bool? ownership, ConfigurationSource? conf /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder IsWeakTypeDefinition(ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder IsWeakTypeDefinition(ConfigurationSource configurationSource) { if (Metadata.DeclaringEntityType.HasDefiningNavigation()) { @@ -1355,7 +1356,7 @@ public virtual InternalRelationshipBuilder IsWeakTypeDefinition(ConfigurationSou /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder OnDelete(DeleteBehavior? deleteBehavior, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder OnDelete(DeleteBehavior? deleteBehavior, ConfigurationSource configurationSource) { if (!CanSetDeleteBehavior(deleteBehavior, configurationSource)) { @@ -1382,7 +1383,7 @@ public virtual bool CanSetDeleteBehavior(DeleteBehavior? deleteBehavior, Configu /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder IsUnique(bool? unique, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder IsUnique(bool? unique, ConfigurationSource configurationSource) { if (Metadata.IsUnique == unique) { @@ -1461,7 +1462,7 @@ private bool CanSetIsUnique(bool? unique, ConfigurationSource? configurationSour /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder DependentEntityType( + public virtual InternalForeignKeyBuilder DependentEntityType( [NotNull] InternalEntityTypeBuilder dependentEntityTypeBuilder, ConfigurationSource configurationSource) => DependentEntityType(dependentEntityTypeBuilder.Metadata, configurationSource); @@ -1471,7 +1472,7 @@ public virtual InternalRelationshipBuilder DependentEntityType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder DependentEntityType( + public virtual InternalForeignKeyBuilder DependentEntityType( [NotNull] Type dependentType, ConfigurationSource configurationSource) => DependentEntityType( ModelBuilder.Entity(dependentType, configurationSource).Metadata, @@ -1483,7 +1484,7 @@ public virtual InternalRelationshipBuilder DependentEntityType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder DependentEntityType( + public virtual InternalForeignKeyBuilder DependentEntityType( [NotNull] string dependentTypeName, ConfigurationSource configurationSource) => DependentEntityType(ModelBuilder.Entity(dependentTypeName, configurationSource).Metadata, configurationSource); @@ -1493,7 +1494,7 @@ public virtual InternalRelationshipBuilder DependentEntityType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder DependentEntityType( + public virtual InternalForeignKeyBuilder DependentEntityType( [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) { Check.NotNull(dependentEntityType, nameof(dependentEntityType)); @@ -1506,7 +1507,7 @@ public virtual InternalRelationshipBuilder DependentEntityType( Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); builder = - (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1525,7 +1526,7 @@ public virtual InternalRelationshipBuilder DependentEntityType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder PrincipalEntityType( + public virtual InternalForeignKeyBuilder PrincipalEntityType( [NotNull] InternalEntityTypeBuilder principalEntityTypeBuilder, ConfigurationSource configurationSource) => PrincipalEntityType(principalEntityTypeBuilder.Metadata, configurationSource); @@ -1535,7 +1536,7 @@ public virtual InternalRelationshipBuilder PrincipalEntityType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder PrincipalEntityType( + public virtual InternalForeignKeyBuilder PrincipalEntityType( [NotNull] Type principalType, ConfigurationSource configurationSource) => PrincipalEntityType( ModelBuilder.Entity(principalType, configurationSource).Metadata, @@ -1547,7 +1548,7 @@ public virtual InternalRelationshipBuilder PrincipalEntityType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder PrincipalEntityType( + public virtual InternalForeignKeyBuilder PrincipalEntityType( [NotNull] string principalTypeName, ConfigurationSource configurationSource) => PrincipalEntityType( ModelBuilder.Entity(principalTypeName, configurationSource).Metadata, @@ -1559,7 +1560,7 @@ public virtual InternalRelationshipBuilder PrincipalEntityType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder PrincipalEntityType( + public virtual InternalForeignKeyBuilder PrincipalEntityType( [NotNull] EntityType principalEntityType, ConfigurationSource configurationSource) { Check.NotNull(principalEntityType, nameof(principalEntityType)); @@ -1572,7 +1573,7 @@ public virtual InternalRelationshipBuilder PrincipalEntityType( Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); builder = - (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1590,13 +1591,13 @@ public virtual InternalRelationshipBuilder PrincipalEntityType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasEntityTypes( + public virtual InternalForeignKeyBuilder HasEntityTypes( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) => HasEntityTypes(principalEntityType, dependentEntityType, configurationSource, configurationSource); - private InternalRelationshipBuilder HasEntityTypes( + private InternalForeignKeyBuilder HasEntityTypes( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, ConfigurationSource? principalEndConfigurationSource, @@ -1615,7 +1616,7 @@ private InternalRelationshipBuilder HasEntityTypes( Metadata.UpdatePrincipalEndConfigurationSource(principalEndConfigurationSource.Value); - return (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(this); + return (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(this); } if (!CanSetRelatedTypes( @@ -1733,7 +1734,7 @@ public virtual bool CanInvert( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder ReuniquifyTemporaryProperties(bool force) + public virtual InternalForeignKeyBuilder ReuniquifyTemporaryProperties(bool force) { if (!force && (Metadata.GetPropertiesConfigurationSource() != null @@ -1809,7 +1810,7 @@ public virtual InternalRelationshipBuilder ReuniquifyTemporaryProperties(bool fo /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasForeignKey( + public virtual InternalForeignKeyBuilder HasForeignKey( [CanBeNull] IReadOnlyList properties, ConfigurationSource configurationSource) => HasForeignKey(properties, Metadata.DeclaringEntityType, configurationSource); @@ -1819,7 +1820,7 @@ public virtual InternalRelationshipBuilder HasForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasForeignKey( + public virtual InternalForeignKeyBuilder HasForeignKey( [CanBeNull] IReadOnlyList propertyNames, ConfigurationSource configurationSource) => HasForeignKey(propertyNames, Metadata.DeclaringEntityType, configurationSource); @@ -1829,7 +1830,7 @@ public virtual InternalRelationshipBuilder HasForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasForeignKey( + public virtual InternalForeignKeyBuilder HasForeignKey( [CanBeNull] IReadOnlyList properties, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) => HasForeignKey( @@ -1843,7 +1844,7 @@ public virtual InternalRelationshipBuilder HasForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasForeignKey( + public virtual InternalForeignKeyBuilder HasForeignKey( [CanBeNull] IReadOnlyList propertyNames, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) => HasForeignKey( @@ -1863,7 +1864,7 @@ public virtual InternalRelationshipBuilder HasForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasForeignKey( + public virtual InternalForeignKeyBuilder HasForeignKey( [CanBeNull] IReadOnlyList properties, ConfigurationSource configurationSource) => HasForeignKey(properties, Metadata.DeclaringEntityType, configurationSource); @@ -1873,7 +1874,7 @@ public virtual InternalRelationshipBuilder HasForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasForeignKey( + public virtual InternalForeignKeyBuilder HasForeignKey( [CanBeNull] IReadOnlyList properties, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) @@ -1899,7 +1900,7 @@ public virtual InternalRelationshipBuilder HasForeignKey( Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); builder = - (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -2049,7 +2050,7 @@ private bool CanSetForeignKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasPrincipalKey( + public virtual InternalForeignKeyBuilder HasPrincipalKey( [NotNull] IReadOnlyList properties, ConfigurationSource configurationSource) => HasPrincipalKey( @@ -2062,7 +2063,7 @@ public virtual InternalRelationshipBuilder HasPrincipalKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasPrincipalKey( + public virtual InternalForeignKeyBuilder HasPrincipalKey( [NotNull] IReadOnlyList propertyNames, ConfigurationSource configurationSource) => HasPrincipalKey( @@ -2075,7 +2076,7 @@ public virtual InternalRelationshipBuilder HasPrincipalKey( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder HasPrincipalKey( + public virtual InternalForeignKeyBuilder HasPrincipalKey( [CanBeNull] IReadOnlyList properties, ConfigurationSource configurationSource) { if (properties == null) @@ -2100,7 +2101,7 @@ public virtual InternalRelationshipBuilder HasPrincipalKey( Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); builder = - (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -2204,7 +2205,7 @@ private bool CanSetPrincipalKey( return true; } - private InternalRelationshipBuilder ReplaceForeignKey( + private InternalForeignKeyBuilder ReplaceForeignKey( ConfigurationSource configurationSource, InternalEntityTypeBuilder principalEntityTypeBuilder = null, InternalEntityTypeBuilder dependentEntityTypeBuilder = null, @@ -2318,7 +2319,7 @@ private InternalRelationshipBuilder ReplaceForeignKey( configurationSource); } - private InternalRelationshipBuilder ReplaceForeignKey( + private InternalForeignKeyBuilder ReplaceForeignKey( [NotNull] InternalEntityTypeBuilder principalEntityTypeBuilder, [NotNull] InternalEntityTypeBuilder dependentEntityTypeBuilder, MemberIdentity? navigationToPrincipal, @@ -2373,7 +2374,7 @@ private InternalRelationshipBuilder ReplaceForeignKey( && Metadata.DeclaringEntityType.IsAssignableFrom(dependentEntityTypeBuilder.Metadata)), "Entity type check failed"); - InternalRelationshipBuilder newRelationshipBuilder; + InternalForeignKeyBuilder newRelationshipBuilder; using (var batch = Metadata.DeclaringEntityType.Model.ConventionDispatcher.DelayConventions()) { newRelationshipBuilder = GetOrCreateRelationshipBuilder( @@ -2770,7 +2771,7 @@ private InternalRelationshipBuilder ReplaceForeignKey( return newRelationshipBuilder; } - private InternalRelationshipBuilder MergeFacetsFrom(Navigation newNavigation, IConventionNavigation oldNavigation) + private InternalForeignKeyBuilder MergeFacetsFrom(Navigation newNavigation, Navigation oldNavigation) { newNavigation?.Builder.MergeAnnotationsFrom(oldNavigation); @@ -2779,10 +2780,12 @@ private InternalRelationshipBuilder MergeFacetsFrom(Navigation newNavigation, IC var propertyAccessModeConfigurationSource = oldNavigation.GetPropertyAccessModeConfigurationSource(); if (propertyAccessModeConfigurationSource.HasValue && builder.CanSetPropertyAccessMode( - oldNavigation.GetPropertyAccessMode(), newNavigation.IsOnDependent, propertyAccessModeConfigurationSource)) + ((IConventionNavigation)oldNavigation).GetPropertyAccessMode(), + newNavigation.IsOnDependent, + propertyAccessModeConfigurationSource)) { builder = builder.UsePropertyAccessMode( - oldNavigation.GetPropertyAccessMode(), newNavigation.IsOnDependent, propertyAccessModeConfigurationSource.Value); + ((IConventionNavigation)oldNavigation).GetPropertyAccessMode(), newNavigation.IsOnDependent, propertyAccessModeConfigurationSource.Value); } var oldFieldInfoConfigurationSource = oldNavigation.GetFieldInfoConfigurationSource(); @@ -2795,7 +2798,7 @@ private InternalRelationshipBuilder MergeFacetsFrom(Navigation newNavigation, IC return builder; } - private InternalRelationshipBuilder GetOrCreateRelationshipBuilder( + private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( EntityType principalEntityType, EntityType dependentEntityType, MemberIdentity? navigationToPrincipal, @@ -3012,7 +3015,7 @@ private InternalRelationshipBuilder GetOrCreateRelationshipBuilder( return newRelationshipBuilder; } - private InternalRelationshipBuilder FindCompatibleRelationship( + private InternalForeignKeyBuilder FindCompatibleRelationship( EntityType principalEntityType, EntityType dependentEntityType, MemberIdentity? navigationToPrincipal, @@ -3024,14 +3027,14 @@ private InternalRelationshipBuilder FindCompatibleRelationship( out bool? existingRelationshipInverted, out bool conflictingRelationshipsFound, out List<( - InternalRelationshipBuilder Builder, + InternalForeignKeyBuilder Builder, bool SameConfigurationSource, Resolution Resolution, bool InverseNavigationShouldBeRemoved)> resolvableRelationships) { existingRelationshipInverted = null; conflictingRelationshipsFound = false; - resolvableRelationships = new List<(InternalRelationshipBuilder, bool, Resolution, bool)>(); + resolvableRelationships = new List<(InternalForeignKeyBuilder, bool, Resolution, bool)>(); var matchingRelationships = FindRelationships( principalEntityType, @@ -3043,7 +3046,7 @@ private InternalRelationshipBuilder FindCompatibleRelationship( .Where(r => r.Metadata != Metadata) .Distinct(); - var unresolvableRelationships = new List(); + var unresolvableRelationships = new List(); foreach (var matchingRelationship in matchingRelationships) { var resolvable = true; @@ -3223,7 +3226,7 @@ private InternalRelationshipBuilder FindCompatibleRelationship( } } - InternalRelationshipBuilder newRelationshipBuilder = null; + InternalForeignKeyBuilder newRelationshipBuilder = null; var candidates = unresolvableRelationships.Concat( resolvableRelationships.Where(r => r.SameConfigurationSource).Concat( @@ -3334,7 +3337,7 @@ public static void ThrowForConflictingNavigation( ? "" : "." + foreignKey.DependentToPrincipal.Name))); - private static IReadOnlyList FindRelationships( + private static IReadOnlyList FindRelationships( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, MemberIdentity? navigationToPrincipal, @@ -3342,7 +3345,7 @@ private static IReadOnlyList FindRelationships( IReadOnlyList dependentProperties, IReadOnlyList principalProperties) { - var existingRelationships = new List(); + var existingRelationships = new List(); if (navigationToPrincipal?.Name != null) { existingRelationships.AddRange( @@ -3391,7 +3394,7 @@ private static IReadOnlyList FindRelationships( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public static InternalRelationshipBuilder FindCurrentRelationshipBuilder( + public static InternalForeignKeyBuilder FindCurrentRelationshipBuilder( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, MemberIdentity? navigationToPrincipal, @@ -3399,7 +3402,7 @@ public static InternalRelationshipBuilder FindCurrentRelationshipBuilder( [CanBeNull] IReadOnlyList dependentProperties, [CanBeNull] IReadOnlyList principalProperties) { - InternalRelationshipBuilder currentRelationship = null; + InternalForeignKeyBuilder currentRelationship = null; var matchingRelationships = FindRelationships( principalEntityType, dependentEntityType, @@ -3473,7 +3476,7 @@ public static InternalRelationshipBuilder FindCurrentRelationshipBuilder( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) + public virtual InternalForeignKeyBuilder Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) { var configurationSource = Metadata.GetConfigurationSource(); var model = Metadata.DeclaringEntityType.Model; diff --git a/src/EFCore/Metadata/Internal/InternalIndexBuilder.cs b/src/EFCore/Metadata/Internal/InternalIndexBuilder.cs index b5e1b6fb615..310741cf321 100644 --- a/src/EFCore/Metadata/Internal/InternalIndexBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalIndexBuilder.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Microsoft.EntityFrameworkCore.Metadata.Internal @@ -12,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class InternalIndexBuilder : InternalModelItemBuilder, IConventionIndexBuilder + public class InternalIndexBuilder : AnnotatableBuilder, IConventionIndexBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/InternalKeyBuilder.cs b/src/EFCore/Metadata/Internal/InternalKeyBuilder.cs index 2209fd5f5f0..92853c0347a 100644 --- a/src/EFCore/Metadata/Internal/InternalKeyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalKeyBuilder.cs @@ -3,6 +3,7 @@ using System.Linq; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Microsoft.EntityFrameworkCore.Metadata.Internal @@ -13,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class InternalKeyBuilder : InternalModelItemBuilder, IConventionKeyBuilder + public class InternalKeyBuilder : AnnotatableBuilder, IConventionKeyBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs index c2d039965e4..601e00640ed 100644 --- a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs @@ -19,7 +19,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class InternalModelBuilder : InternalAnnotatableBuilder, IConventionModelBuilder + public class InternalModelBuilder : AnnotatableBuilder, IConventionModelBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -28,7 +28,7 @@ public class InternalModelBuilder : InternalAnnotatableBuilder, IConventi /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public InternalModelBuilder([NotNull] Model metadata) - : base(metadata) + : base(metadata, null) { } diff --git a/src/EFCore/Metadata/Internal/InternalModelItemBuilder.cs b/src/EFCore/Metadata/Internal/InternalModelItemBuilder.cs deleted file mode 100644 index 8d3f96ab870..00000000000 --- a/src/EFCore/Metadata/Internal/InternalModelItemBuilder.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Diagnostics; -using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Infrastructure; - -namespace Microsoft.EntityFrameworkCore.Metadata.Internal -{ - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public abstract class InternalModelItemBuilder : InternalAnnotatableBuilder - where TMetadata : ConventionAnnotatable - { - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - protected InternalModelItemBuilder([NotNull] TMetadata metadata, [NotNull] InternalModelBuilder modelBuilder) - : base(metadata) - { - ModelBuilder = modelBuilder; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public override InternalModelBuilder ModelBuilder { [DebuggerStepThrough] get; } - } -} diff --git a/src/EFCore/Metadata/Internal/InternalPropertyBaseBuilder`.cs b/src/EFCore/Metadata/Internal/InternalPropertyBaseBuilder`.cs index 9f4f9c5dd45..331052e6085 100644 --- a/src/EFCore/Metadata/Internal/InternalPropertyBaseBuilder`.cs +++ b/src/EFCore/Metadata/Internal/InternalPropertyBaseBuilder`.cs @@ -3,6 +3,7 @@ using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Infrastructure; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -12,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class InternalPropertyBaseBuilder : InternalModelItemBuilder + public class InternalPropertyBaseBuilder : AnnotatableBuilder where TPropertyBase : PropertyBase { /// diff --git a/src/EFCore/Metadata/Internal/InternalServicePropertyBuilder.cs b/src/EFCore/Metadata/Internal/InternalServicePropertyBuilder.cs index 55bbc3a3815..e03cf34e15d 100644 --- a/src/EFCore/Metadata/Internal/InternalServicePropertyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalServicePropertyBuilder.cs @@ -3,6 +3,7 @@ using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Microsoft.EntityFrameworkCore.Metadata.Internal @@ -13,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class InternalServicePropertyBuilder : InternalModelItemBuilder, IConventionServicePropertyBuilder + public class InternalServicePropertyBuilder : AnnotatableBuilder, IConventionServicePropertyBuilder { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs b/src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs index 428430213c4..ba6120c92cd 100644 --- a/src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs @@ -33,7 +33,7 @@ public InternalSkipNavigationBuilder([NotNull] SkipNavigation metadata, [NotNull /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual new InternalSkipNavigationBuilder HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource) + public new virtual InternalSkipNavigationBuilder HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource) => (InternalSkipNavigationBuilder)base.HasField(fieldName, configurationSource); /// @@ -74,7 +74,7 @@ public virtual bool CanSetField([CanBeNull] FieldInfo fieldInfo, ConfigurationSo /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual new InternalSkipNavigationBuilder UsePropertyAccessMode( + public new virtual InternalSkipNavigationBuilder UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, ConfigurationSource configurationSource) => (InternalSkipNavigationBuilder)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); @@ -242,7 +242,7 @@ public virtual InternalSkipNavigationBuilder Attach( var foreignKey = Metadata.ForeignKey; if (foreignKey.Builder == null) { - foreignKey = InternalRelationshipBuilder.FindCurrentRelationshipBuilder( + foreignKey = InternalForeignKeyBuilder.FindCurrentRelationshipBuilder( foreignKey.PrincipalEntityType, foreignKey.DeclaringEntityType, foreignKey.DependentToPrincipal?.CreateMemberIdentity(), diff --git a/src/EFCore/Metadata/Internal/RelationshipSnapshot.cs b/src/EFCore/Metadata/Internal/RelationshipSnapshot.cs index 62a9b74bfee..72ee9226e7b 100644 --- a/src/EFCore/Metadata/Internal/RelationshipSnapshot.cs +++ b/src/EFCore/Metadata/Internal/RelationshipSnapshot.cs @@ -22,7 +22,7 @@ public class RelationshipSnapshot /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public RelationshipSnapshot( - [NotNull] InternalRelationshipBuilder relationship, + [NotNull] InternalForeignKeyBuilder relationship, [CanBeNull] EntityType.Snapshot definedEntityTypeSnapshot, [CanBeNull] List<(SkipNavigation, ConfigurationSource)> referencingSkipNavigations) { @@ -37,7 +37,7 @@ public RelationshipSnapshot( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder Relationship { [DebuggerStepThrough] get; } + public virtual InternalForeignKeyBuilder Relationship { [DebuggerStepThrough] get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -64,7 +64,7 @@ public RelationshipSnapshot( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalRelationshipBuilder Attach([CanBeNull] InternalEntityTypeBuilder entityTypeBuilder = null) + public virtual InternalForeignKeyBuilder Attach([CanBeNull] InternalEntityTypeBuilder entityTypeBuilder = null) { entityTypeBuilder ??= Relationship.Metadata.DeclaringEntityType.Builder; diff --git a/test/EFCore.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs b/test/EFCore.Tests/Infrastructure/AnnotatableBuilderTest.cs similarity index 81% rename from test/EFCore.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs rename to test/EFCore.Tests/Infrastructure/AnnotatableBuilderTest.cs index e8a25c387e0..7e5356e4445 100644 --- a/test/EFCore.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs +++ b/test/EFCore.Tests/Infrastructure/AnnotatableBuilderTest.cs @@ -2,16 +2,18 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Xunit; -namespace Microsoft.EntityFrameworkCore.Metadata.Internal +namespace Microsoft.EntityFrameworkCore.Infrastructure { - public class InternalMetadataBuilderTest + public class AnnotatableBuilderTest { [ConditionalFact] public void Can_only_override_lower_source_annotation() { - var builder = CreateInternalMetadataBuilder(); + var builder = CreateAnnotatableBuilder(); var metadata = builder.Metadata; Assert.NotNull(builder.HasAnnotation("Foo", "1", ConfigurationSource.Convention)); @@ -26,7 +28,7 @@ public void Can_only_override_lower_source_annotation() [ConditionalFact] public void Can_only_override_existing_annotation_explicitly() { - var builder = CreateInternalMetadataBuilder(); + var builder = CreateAnnotatableBuilder(); var metadata = builder.Metadata; metadata["Foo"] = "1"; @@ -42,7 +44,7 @@ public void Can_only_override_existing_annotation_explicitly() [ConditionalFact] public void Annotation_set_explicitly_can_not_be_removed_by_convention() { - var builder = CreateInternalMetadataBuilder(); + var builder = CreateAnnotatableBuilder(); var metadata = builder.Metadata; metadata["Foo"] = "1"; @@ -54,7 +56,7 @@ public void Annotation_set_explicitly_can_not_be_removed_by_convention() Assert.Null(metadata.GetAnnotations().Single().Value); } - private InternalAnnotatableBuilder CreateInternalMetadataBuilder() + private AnnotatableBuilder CreateAnnotatableBuilder() => new InternalModelBuilder(new Model()); } } diff --git a/test/EFCore.Tests/Metadata/Conventions/ForeignKeyPropertyDiscoveryConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/ForeignKeyPropertyDiscoveryConventionTest.cs index 2b86588362e..4c01f3411a3 100644 --- a/test/EFCore.Tests/Metadata/Conventions/ForeignKeyPropertyDiscoveryConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/ForeignKeyPropertyDiscoveryConventionTest.cs @@ -1099,7 +1099,7 @@ private static InternalModelBuilder BuildModel() return modelBuilder; } - private InternalRelationshipBuilder RunConvention(InternalRelationshipBuilder relationshipBuilder) + private InternalForeignKeyBuilder RunConvention(InternalForeignKeyBuilder relationshipBuilder) { var convention = CreateForeignKeyPropertyDiscoveryConvention(); var context = new ConventionContext( @@ -1107,7 +1107,7 @@ private InternalRelationshipBuilder RunConvention(InternalRelationshipBuilder re convention.ProcessForeignKeyAdded(relationshipBuilder, context); if (context.ShouldStopProcessing()) { - return (InternalRelationshipBuilder)context.Result; + return (InternalForeignKeyBuilder)context.Result; } return relationshipBuilder; diff --git a/test/EFCore.Tests/Metadata/Conventions/NavigationAttributeConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/NavigationAttributeConventionTest.cs index 24502d0a550..1388242aa7c 100644 --- a/test/EFCore.Tests/Metadata/Conventions/NavigationAttributeConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/NavigationAttributeConventionTest.cs @@ -807,7 +807,7 @@ private void RunConvention(InternalEntityTypeBuilder entityTypeBuilder) .ProcessEntityTypeAdded(entityTypeBuilder, context); } - private InternalRelationshipBuilder RunConvention(InternalRelationshipBuilder relationshipBuilder) + private InternalForeignKeyBuilder RunConvention(InternalForeignKeyBuilder relationshipBuilder) { var dependencies = CreateDependencies(CreateLogger()); var context = new ConventionContext( @@ -816,10 +816,10 @@ private InternalRelationshipBuilder RunConvention(InternalRelationshipBuilder re new ForeignKeyAttributeConvention(dependencies) .ProcessForeignKeyAdded(relationshipBuilder, context); - return context.ShouldStopProcessing() ? (InternalRelationshipBuilder)context.Result : relationshipBuilder; + return context.ShouldStopProcessing() ? (InternalForeignKeyBuilder)context.Result : relationshipBuilder; } - private void RunConvention(InternalRelationshipBuilder relationshipBuilder, Navigation navigation) + private void RunConvention(InternalForeignKeyBuilder relationshipBuilder, Navigation navigation) { var dependencies = CreateDependencies(CreateLogger()); var context = new ConventionContext( diff --git a/test/EFCore.Tests/Metadata/Conventions/NonNullableNavigationConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/NonNullableNavigationConventionTest.cs index 8b937cd7277..9f5bdafc100 100644 --- a/test/EFCore.Tests/Metadata/Conventions/NonNullableNavigationConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/NonNullableNavigationConventionTest.cs @@ -176,7 +176,7 @@ public void Non_nullability_can_be_specified_on_both_navigations() nameof(Blog), nameof(Blog.BlogDetails), nameof(BlogDetails), nameof(BlogDetails.Blog)), logEntry.Message); } - private Navigation RunConvention(InternalRelationshipBuilder relationshipBuilder, Navigation navigation) + private Navigation RunConvention(InternalForeignKeyBuilder relationshipBuilder, Navigation navigation) { var context = new ConventionContext( relationshipBuilder.Metadata.DeclaringEntityType.Model.ConventionDispatcher); diff --git a/test/EFCore.Tests/Metadata/Conventions/ValueGeneratorConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/ValueGeneratorConventionTest.cs index d2af664c287..9a3bfea5cf9 100644 --- a/test/EFCore.Tests/Metadata/Conventions/ValueGeneratorConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/ValueGeneratorConventionTest.cs @@ -453,7 +453,7 @@ private static void RunConvention(InternalEntityTypeBuilder entityBuilder) new ConventionContext(entityBuilder.Metadata.Model.ConventionDispatcher)); } - private static void RunConvention(InternalRelationshipBuilder foreignKeyBuilder) + private static void RunConvention(InternalForeignKeyBuilder foreignKeyBuilder) { new ValueGenerationConvention(CreateDependencies()) .ProcessForeignKeyAdded(