From 85563581e930fae165f6d1d8d03da407314ea297 Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Tue, 4 May 2021 09:38:16 -0700 Subject: [PATCH] Rename SlimModel to RuntimeModel. Perform other refactorings. Part of #24743 --- .../InMemoryServiceCollectionExtensions.cs | 1 - .../RelationalEntityTypeBuilderExtensions.cs | 2 +- .../Extensions/RelationalModelExtensions.cs | 18 +- .../RelationalConventionSetBuilder.cs | 2 +- ...cs => RelationalRuntimeModelConvention.cs} | 138 ++++++------- .../Metadata/IReadOnlyDbFunctionParameter.cs | 2 +- .../Metadata/Internal/CheckConstraint.cs | 12 +- ...onstraint.cs => RuntimeCheckConstraint.cs} | 8 +- ...SlimDbFunction.cs => RuntimeDbFunction.cs} | 18 +- ...meter.cs => RuntimeDbFunctionParameter.cs} | 8 +- ... => RuntimeRelationalPropertyOverrides.cs} | 8 +- .../{SlimSequence.cs => RuntimeSequence.cs} | 8 +- .../SqlServerAnnotationCodeGenerator.cs | 1 - .../Internal/SqlServerDatabaseCreator.cs | 3 +- .../Internal/InternalEntityEntry.cs | 6 +- src/EFCore/ChangeTracking/ValueComparer`.cs | 2 +- src/EFCore/Infrastructure/ModelValidator.cs | 2 +- .../ProviderConventionSetBuilder.cs | 2 +- ...onvention.cs => RuntimeModelConvention.cs} | 172 ++++++++-------- src/EFCore/Metadata/IKey.cs | 8 + src/EFCore/Metadata/IReadOnlyKey.cs | 8 - src/EFCore/Metadata/IReadOnlyProperty.cs | 2 +- src/EFCore/Metadata/Internal/ForeignKey.cs | 2 +- src/EFCore/Metadata/Internal/IRuntimeModel.cs | 8 + .../Metadata/Internal/InternalModelBuilder.cs | 6 +- ...SlimEntityType.cs => RuntimeEntityType.cs} | 194 +++++++++--------- ...SlimForeignKey.cs => RuntimeForeignKey.cs} | 30 +-- .../{SlimIndex.cs => RuntimeIndex.cs} | 12 +- .../Metadata/{SlimKey.cs => RuntimeKey.cs} | 10 +- .../{SlimModel.cs => RuntimeModel.cs} | 37 ++-- ...SlimNavigation.cs => RuntimeNavigation.cs} | 10 +- .../{SlimProperty.cs => RuntimeProperty.cs} | 28 +-- ...PropertyBase.cs => RuntimePropertyBase.cs} | 6 +- ...eProperty.cs => RuntimeServiceProperty.cs} | 8 +- ...Navigation.cs => RuntimeSkipNavigation.cs} | 20 +- src/EFCore/Properties/CoreStrings.Designer.cs | 12 +- src/EFCore/Properties/CoreStrings.resx | 6 +- 37 files changed, 412 insertions(+), 408 deletions(-) rename src/EFCore.Relational/Metadata/Conventions/{RelationalSlimModelConvention.cs => RelationalRuntimeModelConvention.cs} (73%) rename src/EFCore.Relational/Metadata/{SlimCheckConstraint.cs => RuntimeCheckConstraint.cs} (93%) rename src/EFCore.Relational/Metadata/{SlimDbFunction.cs => RuntimeDbFunction.cs} (94%) rename src/EFCore.Relational/Metadata/{SlimDbFunctionParameter.cs => RuntimeDbFunctionParameter.cs} (95%) rename src/EFCore.Relational/Metadata/{SlimRelationalPropertyOverrides.cs => RuntimeRelationalPropertyOverrides.cs} (89%) rename src/EFCore.Relational/Metadata/{SlimSequence.cs => RuntimeSequence.cs} (96%) rename src/EFCore/Metadata/Conventions/{SlimModelConvention.cs => RuntimeModelConvention.cs} (73%) rename src/EFCore/Metadata/{SlimEntityType.cs => RuntimeEntityType.cs} (88%) rename src/EFCore/Metadata/{SlimForeignKey.cs => RuntimeForeignKey.cs} (91%) rename src/EFCore/Metadata/{SlimIndex.cs => RuntimeIndex.cs} (93%) rename src/EFCore/Metadata/{SlimKey.cs => RuntimeKey.cs} (94%) rename src/EFCore/Metadata/{SlimModel.cs => RuntimeModel.cs} (88%) rename src/EFCore/Metadata/{SlimNavigation.cs => RuntimeNavigation.cs} (94%) rename src/EFCore/Metadata/{SlimProperty.cs => RuntimeProperty.cs} (93%) rename src/EFCore/Metadata/{SlimPropertyBase.cs => RuntimePropertyBase.cs} (96%) rename src/EFCore/Metadata/{SlimServiceProperty.cs => RuntimeServiceProperty.cs} (94%) rename src/EFCore/Metadata/{SlimSkipNavigation.cs => RuntimeSkipNavigation.cs} (91%) diff --git a/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs b/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs index ec3b2a28d31..1427289ebdb 100644 --- a/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs +++ b/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.InMemory.Diagnostics.Internal; using Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal; -using Microsoft.EntityFrameworkCore.InMemory.Internal; using Microsoft.EntityFrameworkCore.InMemory.Metadata.Conventions; using Microsoft.EntityFrameworkCore.InMemory.Query.Internal; using Microsoft.EntityFrameworkCore.InMemory.Storage.Internal; diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs index fe276473156..b730f74f701 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs @@ -862,7 +862,7 @@ public static OwnedNavigationBuilder ToFunction).MakeGenericType(entityType.ClrType ?? typeof(Dictionary))) + name, typeof(IQueryable<>).MakeGenericType(entityType.ClrType)) : null; return function; diff --git a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs index c8decbadfda..4ae4798b476 100644 --- a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs @@ -318,9 +318,7 @@ public static IEnumerable GetSequences(this IReadOnlyModel mo /// The model name of the function. /// The function or if the method is not mapped. public static IReadOnlyDbFunction? FindDbFunction(this IReadOnlyModel model, string name) - => DbFunction.FindDbFunction( - Check.NotNull(model, nameof(model)), - Check.NotNull(name, nameof(name))); + => DbFunction.FindDbFunction(model, Check.NotNull(name, nameof(name))); /// /// Finds a function that is mapped to the method represented by the given name. @@ -329,7 +327,7 @@ public static IEnumerable GetSequences(this IReadOnlyModel mo /// The model name of the function. /// The function or if the method is not mapped. public static IMutableDbFunction? FindDbFunction(this IMutableModel model, string name) - => (IMutableDbFunction?)((IModel)model).FindDbFunction(name); + => (IMutableDbFunction?)((IReadOnlyModel)model).FindDbFunction(name); /// /// Finds a function that is mapped to the method represented by the given name. @@ -338,7 +336,7 @@ public static IEnumerable GetSequences(this IReadOnlyModel mo /// The model name of the function. /// The function or if the method is not mapped. public static IConventionDbFunction? FindDbFunction(this IConventionModel model, string name) - => (IConventionDbFunction?)((IModel)model).FindDbFunction(name); + => (IConventionDbFunction?)((IReadOnlyModel)model).FindDbFunction(name); /// /// Finds a function that is mapped to the method represented by the given name. @@ -455,7 +453,7 @@ public static IConventionDbFunction AddDbFunction( /// Returns all functions contained in the model. /// /// The model to get the functions in. - public static IEnumerable GetDbFunctions(this IModel model) + public static IEnumerable GetDbFunctions(this IReadOnlyModel model) => DbFunction.GetDbFunctions(Check.NotNull(model, nameof(model))); /// @@ -463,21 +461,21 @@ public static IEnumerable GetDbFunctions(this IModel model) /// /// The model to get the functions in. public static IEnumerable GetDbFunctions(this IMutableModel model) - => DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model))).Cast(); + => DbFunction.GetDbFunctions(Check.NotNull(model, nameof(model))).Cast(); /// /// Returns all functions contained in the model. /// /// The model to get the functions in. public static IEnumerable GetDbFunctions(this IConventionModel model) - => DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model))).Cast(); + => DbFunction.GetDbFunctions(Check.NotNull(model, nameof(model))).Cast(); /// /// Returns all functions contained in the model. /// /// The model to get the functions in. - public static IEnumerable GetDbFunctions(this IReadOnlyModel model) - => DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model))); + public static IEnumerable GetDbFunctions(this IModel model) + => DbFunction.GetDbFunctions(Check.NotNull(model, nameof(model))); /// /// Returns the database collation. diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs index 80b48b17400..279648abaae 100644 --- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs +++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs @@ -111,7 +111,7 @@ public override ConventionSet CreateConventionSet() ReplaceConvention( conventionSet.ModelFinalizedConventions, - (SlimModelConvention)new RelationalSlimModelConvention(Dependencies, RelationalDependencies)); + (RuntimeModelConvention)new RelationalRuntimeModelConvention(Dependencies, RelationalDependencies)); return conventionSet; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalSlimModelConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.cs similarity index 73% rename from src/EFCore.Relational/Metadata/Conventions/RelationalSlimModelConvention.cs rename to src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.cs index d4a08b4cfc4..99efe9f486c 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalSlimModelConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.cs @@ -16,14 +16,14 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions /// A convention that creates an optimized copy of the mutable model. This convention is typically /// implemented by database providers to update provider annotations when creating a read-only model. /// - public class RelationalSlimModelConvention : SlimModelConvention + public class RelationalRuntimeModelConvention : RuntimeModelConvention { /// /// Creates a new instance of . /// /// Parameter object containing dependencies for this convention. /// Parameter object containing relational dependencies for this convention. - public RelationalSlimModelConvention( + public RelationalRuntimeModelConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) @@ -41,56 +41,56 @@ public RelationalSlimModelConvention( /// /// The annotations to be processed. /// The source model. - /// The target model that will contain the annotations. + /// The target model that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected override void ProcessModelAnnotations( - Dictionary annotations, IModel model, SlimModel slimModel, bool runtime) + Dictionary annotations, IModel model, RuntimeModel runtimeModel, bool runtime) { - base.ProcessModelAnnotations(annotations, model, slimModel, runtime); + base.ProcessModelAnnotations(annotations, model, runtimeModel, runtime); if (runtime) { annotations[RelationalAnnotationNames.RelationalModel] = - RelationalModel.Create(slimModel, RelationalDependencies.RelationalAnnotationProvider); + RelationalModel.Create(runtimeModel, RelationalDependencies.RelationalAnnotationProvider); } else { if (annotations.TryGetValue(RelationalAnnotationNames.DbFunctions, out var functions)) { - var slimFunctions = new SortedDictionary(); + var runtimeFunctions = new SortedDictionary(); foreach (var functionPair in (SortedDictionary)functions!) { - var slimFunction = Create(functionPair.Value, slimModel); - slimFunctions[functionPair.Key] = slimFunction; + var runtimeFunction = Create(functionPair.Value, runtimeModel); + runtimeFunctions[functionPair.Key] = runtimeFunction; foreach (var parameter in functionPair.Value.Parameters) { - var slimParameter = Create(parameter, slimFunction); + var runtimeParameter = Create(parameter, runtimeFunction); - CreateAnnotations(parameter, slimParameter, static (convention, annotations, source, target, runtime) => + CreateAnnotations(parameter, runtimeParameter, static (convention, annotations, source, target, runtime) => convention.ProcessFunctionParameterAnnotations(annotations, source, target, runtime)); } - CreateAnnotations(functionPair.Value, slimFunction, static (convention, annotations, source, target, runtime) => + CreateAnnotations(functionPair.Value, runtimeFunction, static (convention, annotations, source, target, runtime) => convention.ProcessFunctionAnnotations(annotations, source, target, runtime)); } - annotations[RelationalAnnotationNames.DbFunctions] = slimFunctions; + annotations[RelationalAnnotationNames.DbFunctions] = runtimeFunctions; } if (annotations.TryGetValue(RelationalAnnotationNames.Sequences, out var sequences)) { - var slimSequences = new SortedDictionary<(string, string?), ISequence>(); + var runtimeSequences = new SortedDictionary<(string, string?), ISequence>(); foreach (var sequencePair in (SortedDictionary<(string, string?), ISequence>)sequences!) { - var slimSequence = Create(sequencePair.Value, slimModel); - slimSequences[sequencePair.Key] = slimSequence; + var runtimeSequence = Create(sequencePair.Value, runtimeModel); + runtimeSequences[sequencePair.Key] = runtimeSequence; - CreateAnnotations(sequencePair.Value, slimSequence, static (convention, annotations, source, target, runtime) => + CreateAnnotations(sequencePair.Value, runtimeSequence, static (convention, annotations, source, target, runtime) => convention.ProcessSequenceAnnotations(annotations, source, target, runtime)); } - annotations[RelationalAnnotationNames.Sequences] = slimSequences; + annotations[RelationalAnnotationNames.Sequences] = runtimeSequences; } } } @@ -100,12 +100,12 @@ protected override void ProcessModelAnnotations( /// /// The annotations to be processed. /// The source entity type. - /// The target entity type that will contain the annotations. + /// The target entity type that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected override void ProcessEntityTypeAnnotations( - IDictionary annotations, IEntityType entityType, SlimEntityType slimEntityType, bool runtime) + IDictionary annotations, IEntityType entityType, RuntimeEntityType runtimeEntityType, bool runtime) { - base.ProcessEntityTypeAnnotations(annotations, entityType, slimEntityType, runtime); + base.ProcessEntityTypeAnnotations(annotations, entityType, runtimeEntityType, runtime); if (runtime) { @@ -119,17 +119,17 @@ protected override void ProcessEntityTypeAnnotations( { if (annotations.TryGetValue(RelationalAnnotationNames.CheckConstraints, out var constraints)) { - var slimCheckConstraints = new Dictionary(); + var runtimeCheckConstraints = new Dictionary(); foreach (var constraintPair in (Dictionary?)constraints!) { - var slimCheckConstraint = Create(constraintPair.Value, slimEntityType); - slimCheckConstraints[constraintPair.Key] = slimCheckConstraint; + var runtimeCheckConstraint = Create(constraintPair.Value, runtimeEntityType); + runtimeCheckConstraints[constraintPair.Key] = runtimeCheckConstraint; - CreateAnnotations(constraintPair.Value, slimCheckConstraint, static (convention, annotations, source, target, runtime) => + CreateAnnotations(constraintPair.Value, runtimeCheckConstraint, static (convention, annotations, source, target, runtime) => convention.ProcessCheckConstraintAnnotations(annotations, source, target, runtime)); } - annotations[RelationalAnnotationNames.CheckConstraints] = slimCheckConstraints; + annotations[RelationalAnnotationNames.CheckConstraints] = runtimeCheckConstraints; } // These need to be set explicitly to prevent default values from being generated @@ -145,7 +145,7 @@ protected override void ProcessEntityTypeAnnotations( private void CreateAnnotations( TSource source, TTarget target, - Action, TSource, TTarget, bool> process) + Action, TSource, TTarget, bool> process) where TSource : IAnnotatable where TTarget : AnnotatableBase { @@ -158,10 +158,10 @@ private void CreateAnnotations( target.AddRuntimeAnnotations(annotations); } - private SlimDbFunction Create(IDbFunction function, SlimModel slimModel) - => new SlimDbFunction( + private RuntimeDbFunction Create(IDbFunction function, RuntimeModel runtimeModel) + => new RuntimeDbFunction( function.ModelName, - slimModel, + runtimeModel, function.MethodInfo, function.ReturnType, function.IsScalar, @@ -179,18 +179,18 @@ private SlimDbFunction Create(IDbFunction function, SlimModel slimModel) /// /// The annotations to be processed. /// The source function. - /// The target function that will contain the annotations. + /// The target function that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessFunctionAnnotations( Dictionary annotations, IDbFunction function, - SlimDbFunction slimFunction, + RuntimeDbFunction runtimeFunction, bool runtime) { } - private SlimDbFunctionParameter Create(IDbFunctionParameter parameter, SlimDbFunction slimFunction) - => slimFunction.AddParameter( + private RuntimeDbFunctionParameter Create(IDbFunctionParameter parameter, RuntimeDbFunction runtimeFunction) + => runtimeFunction.AddParameter( parameter.Name, parameter.ClrType, parameter.PropagatesNullability, @@ -202,21 +202,21 @@ private SlimDbFunctionParameter Create(IDbFunctionParameter parameter, SlimDbFun /// /// The annotations to be processed. /// The source function parameter. - /// The target function parameter that will contain the annotations. + /// The target function parameter that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessFunctionParameterAnnotations( Dictionary annotations, IDbFunctionParameter parameter, - SlimDbFunctionParameter slimParameter, + RuntimeDbFunctionParameter runtimeParameter, bool runtime) { } - private SlimSequence Create(ISequence sequence, SlimModel slimModel) - => new SlimSequence( + private RuntimeSequence Create(ISequence sequence, RuntimeModel runtimeModel) + => new RuntimeSequence( sequence.Name, sequence.Schema, - slimModel, + runtimeModel, sequence.Type, sequence.StartValue, sequence.IncrementBy, @@ -229,20 +229,20 @@ private SlimSequence Create(ISequence sequence, SlimModel slimModel) /// /// The annotations to be processed. /// The source sequence. - /// The target sequence that will contain the annotations. + /// The target sequence that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessSequenceAnnotations( Dictionary annotations, ISequence sequence, - SlimSequence slimSequence, + RuntimeSequence runtimeSequence, bool runtime) { } - private SlimCheckConstraint Create(ICheckConstraint checkConstraint, SlimEntityType slimEntityType) - => new SlimCheckConstraint( + private RuntimeCheckConstraint Create(ICheckConstraint checkConstraint, RuntimeEntityType runtimeEntityType) + => new RuntimeCheckConstraint( checkConstraint.Name, - slimEntityType, + runtimeEntityType, checkConstraint.Sql); /// @@ -250,12 +250,12 @@ private SlimCheckConstraint Create(ICheckConstraint checkConstraint, SlimEntityT /// /// The annotations to be processed. /// The source check constraint. - /// The target check constraint that will contain the annotations. + /// The target check constraint that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessCheckConstraintAnnotations( Dictionary annotations, ICheckConstraint checkConstraint, - SlimCheckConstraint slimCheckConstraint, + RuntimeCheckConstraint runtimeCheckConstraint, bool runtime) { } @@ -265,12 +265,12 @@ protected virtual void ProcessCheckConstraintAnnotations( /// /// The annotations to be processed. /// The source property. - /// The target property that will contain the annotations. + /// The target property that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected override void ProcessPropertyAnnotations( - Dictionary annotations, IProperty property, SlimProperty slimProperty, bool runtime) + Dictionary annotations, IProperty property, RuntimeProperty runtimeProperty, bool runtime) { - base.ProcessPropertyAnnotations(annotations, property, slimProperty, runtime); + base.ProcessPropertyAnnotations(annotations, property, runtimeProperty, runtime); if (runtime) { @@ -284,26 +284,26 @@ protected override void ProcessPropertyAnnotations( { if (annotations.TryGetValue(RelationalAnnotationNames.RelationalOverrides, out var overrides)) { - var slimPropertyOverrides = new SortedDictionary(); + var runtimePropertyOverrides = new SortedDictionary(); foreach (var overridesPair in (SortedDictionary?)overrides!) { - var slimOverrides = Create(overridesPair.Value, slimProperty); - slimPropertyOverrides[overridesPair.Key] = slimOverrides; + var runtimeOverrides = Create(overridesPair.Value, runtimeProperty); + runtimePropertyOverrides[overridesPair.Key] = runtimeOverrides; - CreateAnnotations(overridesPair.Value, slimOverrides, static (convention, annotations, source, target, runtime) => + CreateAnnotations(overridesPair.Value, runtimeOverrides, static (convention, annotations, source, target, runtime) => convention.ProcessPropertyOverridesAnnotations(annotations, source, target, runtime)); } - annotations[RelationalAnnotationNames.RelationalOverrides] = slimPropertyOverrides; + annotations[RelationalAnnotationNames.RelationalOverrides] = runtimePropertyOverrides; } } } - private SlimRelationalPropertyOverrides Create( + private RuntimeRelationalPropertyOverrides Create( IRelationalPropertyOverrides propertyOverrides, - SlimProperty slimProperty) - => new SlimRelationalPropertyOverrides( - slimProperty, + RuntimeProperty runtimeProperty) + => new RuntimeRelationalPropertyOverrides( + runtimeProperty, propertyOverrides.ColumnName, propertyOverrides.ColumnNameOverriden); @@ -312,12 +312,12 @@ private SlimRelationalPropertyOverrides Create( /// /// The annotations to be processed. /// The source relational property overrides. - /// The target relational property overrides that will contain the annotations. + /// The target relational property overrides that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessPropertyOverridesAnnotations( Dictionary annotations, IRelationalPropertyOverrides propertyOverrides, - SlimRelationalPropertyOverrides slimPropertyOverrides, + RuntimeRelationalPropertyOverrides runtimePropertyOverrides, bool runtime) { } @@ -327,15 +327,15 @@ protected virtual void ProcessPropertyOverridesAnnotations( /// /// The annotations to be processed. /// The source key. - /// The target key that will contain the annotations. + /// The target key that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected override void ProcessKeyAnnotations( IDictionary annotations, IKey key, - SlimKey slimKey, + RuntimeKey runtimeKey, bool runtime) { - base.ProcessKeyAnnotations(annotations, key, slimKey, runtime); + base.ProcessKeyAnnotations(annotations, key, runtimeKey, runtime); if (runtime) { @@ -348,15 +348,15 @@ protected override void ProcessKeyAnnotations( /// /// The annotations to be processed. /// The source index. - /// The target index that will contain the annotations. + /// The target index that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected override void ProcessIndexAnnotations( Dictionary annotations, IIndex index, - SlimIndex slimIndex, + RuntimeIndex runtimeIndex, bool runtime) { - base.ProcessIndexAnnotations(annotations, index, slimIndex, runtime); + base.ProcessIndexAnnotations(annotations, index, runtimeIndex, runtime); if (runtime) { @@ -369,15 +369,15 @@ protected override void ProcessIndexAnnotations( /// /// The annotations to be processed. /// The source foreign key. - /// The target foreign key that will contain the annotations. + /// The target foreign key that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected override void ProcessForeignKeyAnnotations( Dictionary annotations, IForeignKey foreignKey, - SlimForeignKey slimForeignKey, + RuntimeForeignKey runtimeForeignKey, bool runtime) { - base.ProcessForeignKeyAnnotations(annotations, foreignKey, slimForeignKey, runtime); + base.ProcessForeignKeyAnnotations(annotations, foreignKey, runtimeForeignKey, runtime); if (runtime) { diff --git a/src/EFCore.Relational/Metadata/IReadOnlyDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IReadOnlyDbFunctionParameter.cs index 642d896ec46..11eb283f623 100644 --- a/src/EFCore.Relational/Metadata/IReadOnlyDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IReadOnlyDbFunctionParameter.cs @@ -40,7 +40,7 @@ public interface IReadOnlyDbFunctionParameter : IReadOnlyAnnotatable bool PropagatesNullability { get; } /// - /// Gets the for this parameter. + /// Gets the type mapping for this parameter. /// RelationalTypeMapping? TypeMapping { get; } diff --git a/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs b/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs index c1619523697..1613dba5fc8 100644 --- a/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs @@ -42,21 +42,21 @@ public CheckConstraint( Sql = sql; _configurationSource = configurationSource; - var dataDictionary = GetConstraintsDictionary(EntityType); - if (dataDictionary == null) + var constraints = GetConstraintsDictionary(EntityType); + if (constraints == null) { - dataDictionary = new Dictionary(); - ((IMutableEntityType)EntityType).SetOrRemoveAnnotation(RelationalAnnotationNames.CheckConstraints, dataDictionary); + constraints = new Dictionary(); + ((IMutableEntityType)EntityType).SetOrRemoveAnnotation(RelationalAnnotationNames.CheckConstraints, constraints); } - if (dataDictionary.ContainsKey(Name)) + if (constraints.ContainsKey(Name)) { throw new InvalidOperationException(RelationalStrings.DuplicateCheckConstraint(Name, EntityType.DisplayName())); } EnsureMutable(); - dataDictionary.Add(name, this); + constraints.Add(name, this); } /// diff --git a/src/EFCore.Relational/Metadata/SlimCheckConstraint.cs b/src/EFCore.Relational/Metadata/RuntimeCheckConstraint.cs similarity index 93% rename from src/EFCore.Relational/Metadata/SlimCheckConstraint.cs rename to src/EFCore.Relational/Metadata/RuntimeCheckConstraint.cs index 2a6dcb8d79b..968d63e6551 100644 --- a/src/EFCore.Relational/Metadata/SlimCheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/RuntimeCheckConstraint.cs @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents a check constraint in the . /// - public class SlimCheckConstraint : AnnotatableBase, ICheckConstraint + public class RuntimeCheckConstraint : AnnotatableBase, ICheckConstraint { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -18,9 +18,9 @@ public class SlimCheckConstraint : AnnotatableBase, ICheckConstraint /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimCheckConstraint( + public RuntimeCheckConstraint( string name, - SlimEntityType entityType, + RuntimeEntityType entityType, string sql) { EntityType = entityType; @@ -31,7 +31,7 @@ public SlimCheckConstraint( /// /// Gets the entity type on which this check constraint is defined. /// - public virtual SlimEntityType EntityType { get; } + public virtual RuntimeEntityType EntityType { get; } /// /// Gets the name of the check constraint in the database. diff --git a/src/EFCore.Relational/Metadata/SlimDbFunction.cs b/src/EFCore.Relational/Metadata/RuntimeDbFunction.cs similarity index 94% rename from src/EFCore.Relational/Metadata/SlimDbFunction.cs rename to src/EFCore.Relational/Metadata/RuntimeDbFunction.cs index 4ae3e078f38..1fe7fa8d3fe 100644 --- a/src/EFCore.Relational/Metadata/SlimDbFunction.cs +++ b/src/EFCore.Relational/Metadata/RuntimeDbFunction.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents a relational database function in a model. /// - public class SlimDbFunction : AnnotatableBase, IRuntimeDbFunction + public class RuntimeDbFunction : AnnotatableBase, IRuntimeDbFunction { - private readonly List _parameters = new(); + private readonly List _parameters = new(); private readonly MethodInfo? _methodInfo; private readonly Type _returnType; private readonly bool _isScalar; @@ -39,9 +39,9 @@ public class SlimDbFunction : AnnotatableBase, IRuntimeDbFunction /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimDbFunction( + public RuntimeDbFunction( string modelName, - SlimModel model, + RuntimeModel model, MethodInfo? methodInfo, Type returnType, bool scalar, @@ -72,7 +72,7 @@ public SlimDbFunction( /// /// Gets the model in which this function is defined. /// - public virtual SlimModel Model { get; } + public virtual RuntimeModel Model { get; } /// /// Gets the name of the function in the model. @@ -88,22 +88,22 @@ public SlimDbFunction( /// The store type of this parameter. /// The for this parameter. /// The new parameter. - public virtual SlimDbFunctionParameter AddParameter( + public virtual RuntimeDbFunctionParameter AddParameter( string name, Type clrType, bool propagatesNullability, string storeType, RelationalTypeMapping? typeMapping = null) { - var slimFunctionParameter = new SlimDbFunctionParameter(this, + var runtimeFunctionParameter = new RuntimeDbFunctionParameter(this, name, clrType, propagatesNullability, storeType, typeMapping); - _parameters.Add(slimFunctionParameter); - return slimFunctionParameter; + _parameters.Add(runtimeFunctionParameter); + return runtimeFunctionParameter; } /// diff --git a/src/EFCore.Relational/Metadata/SlimDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/RuntimeDbFunctionParameter.cs similarity index 95% rename from src/EFCore.Relational/Metadata/SlimDbFunctionParameter.cs rename to src/EFCore.Relational/Metadata/RuntimeDbFunctionParameter.cs index 969e06206c7..639b71f4327 100644 --- a/src/EFCore.Relational/Metadata/SlimDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/RuntimeDbFunctionParameter.cs @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents a function parameter. /// - public class SlimDbFunctionParameter : AnnotatableBase, IRuntimeDbFunctionParameter + public class RuntimeDbFunctionParameter : AnnotatableBase, IRuntimeDbFunctionParameter { private readonly string _name; private readonly Type _clrType; @@ -29,8 +29,8 @@ public class SlimDbFunctionParameter : AnnotatableBase, IRuntimeDbFunctionParame /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimDbFunctionParameter( - SlimDbFunction function, + public RuntimeDbFunctionParameter( + RuntimeDbFunction function, string name, Type clrType, bool propagatesNullability, @@ -57,7 +57,7 @@ public virtual string Name /// /// Gets the function to which this parameter belongs. /// - public virtual SlimDbFunction Function { get; } + public virtual RuntimeDbFunction Function { get; } /// /// Returns a string that represents the current object. diff --git a/src/EFCore.Relational/Metadata/SlimRelationalPropertyOverrides.cs b/src/EFCore.Relational/Metadata/RuntimeRelationalPropertyOverrides.cs similarity index 89% rename from src/EFCore.Relational/Metadata/SlimRelationalPropertyOverrides.cs rename to src/EFCore.Relational/Metadata/RuntimeRelationalPropertyOverrides.cs index f0c5f0beb72..ecd618a8829 100644 --- a/src/EFCore.Relational/Metadata/SlimRelationalPropertyOverrides.cs +++ b/src/EFCore.Relational/Metadata/RuntimeRelationalPropertyOverrides.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents property facet overrides for a particular table-like store object. /// - public class SlimRelationalPropertyOverrides : AnnotatableBase, IRelationalPropertyOverrides + public class RuntimeRelationalPropertyOverrides : AnnotatableBase, IRelationalPropertyOverrides { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -19,8 +19,8 @@ public class SlimRelationalPropertyOverrides : AnnotatableBase, IRelationalPrope /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimRelationalPropertyOverrides( - SlimProperty property, + public RuntimeRelationalPropertyOverrides( + RuntimeProperty property, string? columnName, bool columnNameOverriden) { @@ -34,7 +34,7 @@ public SlimRelationalPropertyOverrides( /// /// Gets the property for which the overrides are applied. /// - public virtual SlimProperty Property { get; } + public virtual RuntimeProperty Property { get; } /// IProperty IRelationalPropertyOverrides.Property diff --git a/src/EFCore.Relational/Metadata/SlimSequence.cs b/src/EFCore.Relational/Metadata/RuntimeSequence.cs similarity index 96% rename from src/EFCore.Relational/Metadata/SlimSequence.cs rename to src/EFCore.Relational/Metadata/RuntimeSequence.cs index f140e2d75b4..1a6bbbbb610 100644 --- a/src/EFCore.Relational/Metadata/SlimSequence.cs +++ b/src/EFCore.Relational/Metadata/RuntimeSequence.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents a database sequence in the model. /// - public class SlimSequence : AnnotatableBase, ISequence + public class RuntimeSequence : AnnotatableBase, ISequence { private readonly string? _schema; private readonly Type _type; @@ -27,10 +27,10 @@ public class SlimSequence : AnnotatableBase, ISequence /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimSequence( + public RuntimeSequence( string name, string? schema, - SlimModel model, + RuntimeModel model, Type type, long startValue, int incrementBy, @@ -52,7 +52,7 @@ public SlimSequence( /// /// Gets the model in which this sequence is defined. /// - public virtual SlimModel Model { get; } + public virtual RuntimeModel Model { get; } /// /// Gets the name of the sequence in the database. diff --git a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs index 945cc7464b2..78e99f0d9ca 100644 --- a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs +++ b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs index 6614c2d0c84..9835aa489ed 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs @@ -179,7 +179,8 @@ private IReadOnlyList CreateCreateOperations() { Name = builder.InitialCatalog, FileName = builder.AttachDBFilename, - Collation = Dependencies.CurrentContext.Context.GetService().Model.GetCollation() + Collation = Dependencies.CurrentContext.Context.GetService() + .Model.GetRelationalModel().Collation } }, null); diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs index 8631fb4174b..8596f02798f 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs @@ -559,8 +559,8 @@ public virtual bool HasTemporaryValue(IProperty property) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual void PropagateValue( - InternalEntityEntry principalEntry, - IProperty principalProperty, + InternalEntityEntry principalEntry, + IProperty principalProperty, IProperty dependentProperty, bool isMaterialization = false, bool setModified = true) @@ -1334,7 +1334,7 @@ public virtual void AcceptChanges() _storeGeneratedValues = new SidecarValues(); _temporaryValues = new SidecarValues(); } - + _stateData.FlagAllProperties(EntityType.PropertyCount(), PropertyFlag.IsTemporary, false); var currentState = EntityState; diff --git a/src/EFCore/ChangeTracking/ValueComparer`.cs b/src/EFCore/ChangeTracking/ValueComparer`.cs index d0847045c28..5e170c47655 100644 --- a/src/EFCore/ChangeTracking/ValueComparer`.cs +++ b/src/EFCore/ChangeTracking/ValueComparer`.cs @@ -290,7 +290,7 @@ public virtual int GetHashCode(T instance) /// The instance. /// The snapshot. public override object? Snapshot(object? instance) - => instance == null ? null : (object?)Snapshot((T?)instance); + => instance == null ? null : Snapshot((T?)instance); /// /// diff --git a/src/EFCore/Infrastructure/ModelValidator.cs b/src/EFCore/Infrastructure/ModelValidator.cs index cc79ef7bce8..1b3b969c06d 100644 --- a/src/EFCore/Infrastructure/ModelValidator.cs +++ b/src/EFCore/Infrastructure/ModelValidator.cs @@ -150,7 +150,7 @@ protected virtual void ValidatePropertyMapping( { var unmappedProperty = entityType.GetDeclaredProperties().FirstOrDefault( p => (!ConfigurationSource.Convention.Overrides(p.GetConfigurationSource()) - // Use a better condition of non-persisted properties when issue#14121 is implemented + // Use a better condition for non-persisted properties when issue #14121 is implemented || !p.IsImplicitlyCreated()) && p.FindTypeMapping() == null); diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs index a4a2dcc9b57..7eb7d42e967 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs @@ -236,7 +236,7 @@ public virtual ConventionSet CreateConventionSet() conventionSet.ModelFinalizingConventions.Add(inversePropertyAttributeConvention); conventionSet.ModelFinalizingConventions.Add(backingFieldConvention); - conventionSet.ModelFinalizedConventions.Add(new SlimModelConvention(Dependencies)); + conventionSet.ModelFinalizedConventions.Add(new RuntimeModelConvention(Dependencies)); return conventionSet; } diff --git a/src/EFCore/Metadata/Conventions/SlimModelConvention.cs b/src/EFCore/Metadata/Conventions/RuntimeModelConvention.cs similarity index 73% rename from src/EFCore/Metadata/Conventions/SlimModelConvention.cs rename to src/EFCore/Metadata/Conventions/RuntimeModelConvention.cs index 70877f9a235..004a6390953 100644 --- a/src/EFCore/Metadata/Conventions/SlimModelConvention.cs +++ b/src/EFCore/Metadata/Conventions/RuntimeModelConvention.cs @@ -19,13 +19,13 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions /// A convention that creates an optimized copy of the mutable model. This convention is typically /// implemented by database providers to update provider annotations when creating a read-only model. /// - public class SlimModelConvention : IModelFinalizedConvention + public class RuntimeModelConvention : IModelFinalizedConvention { /// - /// Creates a new instance of . + /// Creates a new instance of . /// /// Parameter object containing dependencies for this convention. - public SlimModelConvention( + public RuntimeModelConvention( ProviderConventionSetBuilderDependencies dependencies) { Dependencies = dependencies; @@ -48,116 +48,116 @@ public virtual IModel ProcessModelFinalized(IModel model) /// /// The source model. /// An optimized model. - protected virtual SlimModel Create(IModel model) + protected virtual RuntimeModel Create(IModel model) { - var slimModel = new SlimModel(model.ModelDependencies!, ((IRuntimeModel)model).SkipDetectChanges); + var runtimeModel = new RuntimeModel(model.ModelDependencies!, ((IRuntimeModel)model).SkipDetectChanges); var entityTypes = Sort(model.GetEntityTypes()); - var entityTypePairs = new List<(IEntityType Source, SlimEntityType Target)>(entityTypes.Count); + var entityTypePairs = new List<(IEntityType Source, RuntimeEntityType Target)>(entityTypes.Count); foreach (var entityType in entityTypes) { - var slimEntityType = Create(entityType, slimModel); - entityTypePairs.Add((entityType, slimEntityType)); + var runtimeEntityType = Create(entityType, runtimeModel); + entityTypePairs.Add((entityType, runtimeEntityType)); foreach (var property in entityType.GetDeclaredProperties()) { - var slimProperty = Create(property, slimEntityType); - CreateAnnotations(property, slimProperty, static (convention, annotations, source, target, runtime) => + var runtimeProperty = Create(property, runtimeEntityType); + CreateAnnotations(property, runtimeProperty, static (convention, annotations, source, target, runtime) => convention.ProcessPropertyAnnotations(annotations, source, target, runtime)); } foreach (var serviceProperty in entityType.GetDeclaredServiceProperties()) { - var slimServiceProperty = Create(serviceProperty, slimEntityType); - CreateAnnotations(serviceProperty, slimServiceProperty, static (convention, annotations, source, target, runtime) => + var runtimeServiceProperty = Create(serviceProperty, runtimeEntityType); + CreateAnnotations(serviceProperty, runtimeServiceProperty, static (convention, annotations, source, target, runtime) => convention.ProcessServicePropertyAnnotations(annotations, source, target, runtime)); - slimServiceProperty.ParameterBinding = - (ServiceParameterBinding)Create(serviceProperty.ParameterBinding, slimEntityType); + runtimeServiceProperty.ParameterBinding = + (ServiceParameterBinding)Create(serviceProperty.ParameterBinding, runtimeEntityType); } foreach (var key in entityType.GetDeclaredKeys()) { - var slimKey = Create(key, slimEntityType); + var runtimeKey = Create(key, runtimeEntityType); if (key.IsPrimaryKey()) { - slimEntityType.SetPrimaryKey(slimKey); + runtimeEntityType.SetPrimaryKey(runtimeKey); } - CreateAnnotations(key, slimKey, static (convention, annotations, source, target, runtime) => + CreateAnnotations(key, runtimeKey, static (convention, annotations, source, target, runtime) => convention.ProcessKeyAnnotations(annotations, source, target, runtime)); } foreach (var index in entityType.GetDeclaredIndexes()) { - var slimIndex = Create(index, slimEntityType); - CreateAnnotations(index, slimIndex, static (convention, annotations, source, target, runtime) => + var runtimeIndex = Create(index, runtimeEntityType); + CreateAnnotations(index, runtimeIndex, static (convention, annotations, source, target, runtime) => convention.ProcessIndexAnnotations(annotations, source, target, runtime)); } - slimEntityType.ConstructorBinding = Create(entityType.ConstructorBinding, slimEntityType); - slimEntityType.ServiceOnlyConstructorBinding = - Create(((IRuntimeEntityType)entityType).ServiceOnlyConstructorBinding, slimEntityType); + runtimeEntityType.ConstructorBinding = Create(entityType.ConstructorBinding, runtimeEntityType); + runtimeEntityType.ServiceOnlyConstructorBinding = + Create(((IRuntimeEntityType)entityType).ServiceOnlyConstructorBinding, runtimeEntityType); } - foreach (var (entityType, slimEntityType) in entityTypePairs) + foreach (var (entityType, runtimeEntityType) in entityTypePairs) { foreach (var foreignKey in entityType.GetDeclaredForeignKeys()) { - var slimForeignKey = Create(foreignKey, slimEntityType); + var runtimeForeignKey = Create(foreignKey, runtimeEntityType); var navigation = foreignKey.DependentToPrincipal; if (navigation != null) { - var slimNavigation = Create(navigation, slimForeignKey); - CreateAnnotations(navigation, slimNavigation, static (convention, annotations, source, target, runtime) => + var runtimeNavigation = Create(navigation, runtimeForeignKey); + CreateAnnotations(navigation, runtimeNavigation, static (convention, annotations, source, target, runtime) => convention.ProcessNavigationAnnotations(annotations, source, target, runtime)); } navigation = foreignKey.PrincipalToDependent; if (navigation != null) { - var slimNavigation = Create(navigation, slimForeignKey); - CreateAnnotations(navigation, slimNavigation, static (convention, annotations, source, target, runtime) => + var runtimeNavigation = Create(navigation, runtimeForeignKey); + CreateAnnotations(navigation, runtimeNavigation, static (convention, annotations, source, target, runtime) => convention.ProcessNavigationAnnotations(annotations, source, target, runtime)); } - CreateAnnotations(foreignKey, slimForeignKey, static (convention, annotations, source, target, runtime) => + CreateAnnotations(foreignKey, runtimeForeignKey, static (convention, annotations, source, target, runtime) => convention.ProcessForeignKeyAnnotations(annotations, source, target, runtime)); } } - foreach (var (entityType, slimEntityType) in entityTypePairs) + foreach (var (entityType, runtimeEntityType) in entityTypePairs) { foreach (var navigation in entityType.GetDeclaredSkipNavigations()) { - var slimNavigation = Create(navigation, slimEntityType); + var runtimeNavigation = Create(navigation, runtimeEntityType); - var inverse = slimNavigation.TargetEntityType.FindSkipNavigation(navigation.Inverse.Name); + var inverse = runtimeNavigation.TargetEntityType.FindSkipNavigation(navigation.Inverse.Name); if (inverse != null) { - slimNavigation.Inverse = inverse; - inverse.Inverse = slimNavigation; + runtimeNavigation.Inverse = inverse; + inverse.Inverse = runtimeNavigation; } - CreateAnnotations(navigation, slimNavigation, static (convention, annotations, source, target, runtime) => + CreateAnnotations(navigation, runtimeNavigation, static (convention, annotations, source, target, runtime) => convention.ProcessSkipNavigationAnnotations(annotations, source, target, runtime)); } - CreateAnnotations(entityType, slimEntityType, static (convention, annotations, source, target, runtime) => + CreateAnnotations(entityType, runtimeEntityType, static (convention, annotations, source, target, runtime) => convention.ProcessEntityTypeAnnotations(annotations, source, target, runtime)); } - CreateAnnotations(model, slimModel, static (convention, annotations, source, target, runtime) => + CreateAnnotations(model, runtimeModel, static (convention, annotations, source, target, runtime) => convention.ProcessModelAnnotations(annotations, source, target, runtime)); - return slimModel; + return runtimeModel; } private void CreateAnnotations( TSource source, TTarget target, - Action, TSource, TTarget, bool> process) + Action, TSource, TTarget, bool> process) where TSource : IAnnotatable where TTarget : AnnotatableBase { @@ -175,18 +175,18 @@ private void CreateAnnotations( /// /// The annotations to be processed. /// The source model. - /// The target model that will contain the annotations. + /// The target model that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessModelAnnotations( Dictionary annotations, IModel model, - SlimModel slimModel, + RuntimeModel runtimeModel, bool runtime) { if (runtime) { annotations.Remove(CoreAnnotationNames.ModelDependencies); - annotations[CoreAnnotationNames.ReadOnlyModel] = slimModel; + annotations[CoreAnnotationNames.ReadOnlyModel] = runtimeModel; } else { @@ -207,7 +207,7 @@ private static IReadOnlyList Sort(IEnumerable entityTy return entityTypeGraph.TopologicalSort(); } - private SlimEntityType Create(IEntityType entityType, SlimModel model) + private RuntimeEntityType Create(IEntityType entityType, RuntimeModel model) => model.AddEntityType(entityType.Name, entityType.ClrType, entityType.HasSharedClrType, @@ -217,14 +217,14 @@ private SlimEntityType Create(IEntityType entityType, SlimModel model) entityType.FindIndexerPropertyInfo(), entityType.IsPropertyBag); - private ParameterBinding Create(ParameterBinding parameterBinding, SlimEntityType entityType) + private ParameterBinding Create(ParameterBinding parameterBinding, RuntimeEntityType entityType) => parameterBinding.With(parameterBinding.ConsumedProperties.Select(property => (entityType.FindProperty(property.Name) ?? entityType.FindServiceProperty(property.Name) ?? entityType.FindNavigation(property.Name) ?? (IPropertyBase?)entityType.FindSkipNavigation(property.Name))!).ToArray()); - private InstantiationBinding? Create(InstantiationBinding? instantiationBinding, SlimEntityType entityType) + private InstantiationBinding? Create(InstantiationBinding? instantiationBinding, RuntimeEntityType entityType) => instantiationBinding?.With(instantiationBinding.ParameterBindings.Select(binding => Create(binding, entityType)).ToList()); /// @@ -232,12 +232,12 @@ private ParameterBinding Create(ParameterBinding parameterBinding, SlimEntityTyp /// /// The annotations to be processed. /// The source entity type. - /// The target entity type that will contain the annotations. + /// The target entity type that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessEntityTypeAnnotations( IDictionary annotations, IEntityType entityType, - SlimEntityType slimEntityType, + RuntimeEntityType runtimeEntityType, bool runtime) { if (!runtime) @@ -249,21 +249,21 @@ protected virtual void ProcessEntityTypeAnnotations( if (annotations.TryGetValue(CoreAnnotationNames.QueryFilter, out var queryFilter)) { annotations[CoreAnnotationNames.QueryFilter] = - new QueryRootRewritingExpressionVisitor(slimEntityType.Model).Rewrite((Expression)queryFilter!); + new QueryRootRewritingExpressionVisitor(runtimeEntityType.Model).Rewrite((Expression)queryFilter!); } #pragma warning disable CS0612 // Type or member is obsolete if (annotations.TryGetValue(CoreAnnotationNames.DefiningQuery, out var definingQuery)) { annotations[CoreAnnotationNames.DefiningQuery] = - new QueryRootRewritingExpressionVisitor(slimEntityType.Model).Rewrite((Expression)definingQuery!); + new QueryRootRewritingExpressionVisitor(runtimeEntityType.Model).Rewrite((Expression)definingQuery!); } #pragma warning restore CS0612 // Type or member is obsolete } } - private SlimProperty Create(IProperty property, SlimEntityType slimEntityType) - => slimEntityType.AddProperty( + private RuntimeProperty Create(IProperty property, RuntimeEntityType runtimeEntityType) + => runtimeEntityType.AddProperty( property.Name, property.ClrType, property.PropertyInfo, @@ -290,12 +290,12 @@ private SlimProperty Create(IProperty property, SlimEntityType slimEntityType) /// /// The annotations to be processed. /// The source property. - /// The target property that will contain the annotations. + /// The target property that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessPropertyAnnotations( Dictionary annotations, IProperty property, - SlimProperty slimProperty, + RuntimeProperty runtimeProperty, bool runtime) { if (!runtime) @@ -317,8 +317,8 @@ protected virtual void ProcessPropertyAnnotations( } } - private SlimServiceProperty Create(IServiceProperty property, SlimEntityType slimEntityType) - => slimEntityType.AddServiceProperty( + private RuntimeServiceProperty Create(IServiceProperty property, RuntimeEntityType runtimeEntityType) + => runtimeEntityType.AddServiceProperty( property.Name, property.PropertyInfo, property.FieldInfo, @@ -329,12 +329,12 @@ private SlimServiceProperty Create(IServiceProperty property, SlimEntityType sli /// /// The annotations to be processed. /// The source service property. - /// The target service property that will contain the annotations. + /// The target service property that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessServicePropertyAnnotations( Dictionary annotations, IServiceProperty property, - SlimServiceProperty slimProperty, + RuntimeServiceProperty runtimeProperty, bool runtime) { if (!runtime) @@ -343,27 +343,27 @@ protected virtual void ProcessServicePropertyAnnotations( } } - private SlimKey Create(IKey key, SlimEntityType slimEntityType) - => slimEntityType.AddKey(slimEntityType.FindProperties(key.Properties.Select(p => p.Name))!); + private RuntimeKey Create(IKey key, RuntimeEntityType runtimeEntityType) + => runtimeEntityType.AddKey(runtimeEntityType.FindProperties(key.Properties.Select(p => p.Name))!); /// /// Updates the key annotations that will be set on the read-only object. /// /// The annotations to be processed. /// The source key. - /// The target key that will contain the annotations. + /// The target key that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessKeyAnnotations( IDictionary annotations, IKey key, - SlimKey slimKey, + RuntimeKey runtimeKey, bool runtime) { } - private SlimIndex Create(IIndex index, SlimEntityType slimEntityType) - => slimEntityType.AddIndex( - slimEntityType.FindProperties(index.Properties.Select(p => p.Name))!, + private RuntimeIndex Create(IIndex index, RuntimeEntityType runtimeEntityType) + => runtimeEntityType.AddIndex( + runtimeEntityType.FindProperties(index.Properties.Select(p => p.Name))!, index.Name, index.IsUnique); @@ -372,21 +372,21 @@ private SlimIndex Create(IIndex index, SlimEntityType slimEntityType) /// /// The annotations to be processed. /// The source index. - /// The target index that will contain the annotations. + /// The target index that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessIndexAnnotations( Dictionary annotations, IIndex index, - SlimIndex slimIndex, + RuntimeIndex runtimeIndex, bool runtime) { } - private SlimForeignKey Create(IForeignKey foreignKey, SlimEntityType slimEntityType) + private RuntimeForeignKey Create(IForeignKey foreignKey, RuntimeEntityType runtimeEntityType) { - var principalEntityType = slimEntityType.Model.FindEntityType(foreignKey.PrincipalEntityType.Name)!; - return slimEntityType.AddForeignKey( - slimEntityType.FindProperties(foreignKey.Properties.Select(p => p.Name))!, + var principalEntityType = runtimeEntityType.Model.FindEntityType(foreignKey.PrincipalEntityType.Name)!; + return runtimeEntityType.AddForeignKey( + runtimeEntityType.FindProperties(foreignKey.Properties.Select(p => p.Name))!, GetKey(foreignKey.PrincipalKey, principalEntityType), principalEntityType, foreignKey.DeleteBehavior, @@ -401,24 +401,24 @@ private SlimForeignKey Create(IForeignKey foreignKey, SlimEntityType slimEntityT /// /// The annotations to be processed. /// The source foreign key. - /// The target foreign key that will contain the annotations. + /// The target foreign key that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessForeignKeyAnnotations( Dictionary annotations, IForeignKey foreignKey, - SlimForeignKey slimForeignKey, + RuntimeForeignKey runtimeForeignKey, bool runtime) { } - private SlimNavigation Create(INavigation navigation, SlimForeignKey slimForeigKey) - => (navigation.IsOnDependent ? slimForeigKey.DeclaringEntityType : slimForeigKey.PrincipalEntityType) + private RuntimeNavigation Create(INavigation navigation, RuntimeForeignKey runtimeForeigKey) + => (navigation.IsOnDependent ? runtimeForeigKey.DeclaringEntityType : runtimeForeigKey.PrincipalEntityType) .AddNavigation( navigation.Name, navigation.ClrType, navigation.PropertyInfo, navigation.FieldInfo, - slimForeigKey, + runtimeForeigKey, navigation.IsOnDependent, navigation.GetPropertyAccessMode(), navigation.IsEagerLoaded); @@ -428,12 +428,12 @@ private SlimNavigation Create(INavigation navigation, SlimForeignKey slimForeigK /// /// The annotations to be processed. /// The source navigation. - /// The target navigation that will contain the annotations. + /// The target navigation that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessNavigationAnnotations( Dictionary annotations, INavigation navigation, - SlimNavigation slimNavigation, + RuntimeNavigation runtimeNavigation, bool runtime) { if (!runtime) @@ -443,14 +443,14 @@ protected virtual void ProcessNavigationAnnotations( } } - private SlimSkipNavigation Create(ISkipNavigation navigation, SlimEntityType slimEntityType) - => slimEntityType.AddSkipNavigation( + private RuntimeSkipNavigation Create(ISkipNavigation navigation, RuntimeEntityType runtimeEntityType) + => runtimeEntityType.AddSkipNavigation( navigation.Name, navigation.ClrType, navigation.PropertyInfo, navigation.FieldInfo, - slimEntityType.Model.FindEntityType(navigation.TargetEntityType.Name)!, - GetForeignKey(navigation.ForeignKey, slimEntityType.Model.FindEntityType(navigation.ForeignKey.DeclaringEntityType.Name)!), + runtimeEntityType.Model.FindEntityType(navigation.TargetEntityType.Name)!, + GetForeignKey(navigation.ForeignKey, runtimeEntityType.Model.FindEntityType(navigation.ForeignKey.DeclaringEntityType.Name)!), navigation.IsCollection, navigation.IsOnDependent, navigation.GetPropertyAccessMode(), @@ -462,7 +462,7 @@ private SlimSkipNavigation Create(ISkipNavigation navigation, SlimEntityType sli /// The original foreign key. /// The declaring entity type. /// The corresponding read-optimized foreign key. - protected virtual SlimForeignKey GetForeignKey(IForeignKey foreignKey, SlimEntityType entityType) + protected virtual RuntimeForeignKey GetForeignKey(IForeignKey foreignKey, RuntimeEntityType entityType) => entityType.FindDeclaredForeignKeys( entityType.FindProperties(foreignKey.Properties.Select(p => p.Name))!) .Single(fk => fk.PrincipalEntityType.Name == foreignKey.PrincipalEntityType.Name @@ -475,7 +475,7 @@ protected virtual SlimForeignKey GetForeignKey(IForeignKey foreignKey, SlimEntit /// The original key. /// The declaring entity type. /// The corresponding read-optimized key. - protected virtual SlimKey GetKey(IKey key, SlimEntityType entityType) + protected virtual RuntimeKey GetKey(IKey key, RuntimeEntityType entityType) => entityType.FindKey(entityType.FindProperties(key.Properties.Select(p => p.Name))!)!; /// @@ -484,7 +484,7 @@ protected virtual SlimKey GetKey(IKey key, SlimEntityType entityType) /// The original index. /// The declaring entity type. /// The corresponding read-optimized index. - protected virtual SlimIndex GetIndex(IIndex index, SlimEntityType entityType) + protected virtual RuntimeIndex GetIndex(IIndex index, RuntimeEntityType entityType) => index.Name == null ? entityType.FindIndex(entityType.FindProperties(index.Properties.Select(p => p.Name))!)! : entityType.FindIndex(index.Name)!; @@ -494,12 +494,12 @@ protected virtual SlimIndex GetIndex(IIndex index, SlimEntityType entityType) /// /// The annotations to be processed. /// The source skip navigation. - /// The target skip navigation that will contain the annotations. + /// The target skip navigation that will contain the annotations. /// Indicates whether the given annotations are runtime annotations. protected virtual void ProcessSkipNavigationAnnotations( Dictionary annotations, ISkipNavigation skipNavigation, - SlimSkipNavigation slimSkipNavigation, + RuntimeSkipNavigation runtimeSkipNavigation, bool runtime) { if (!runtime) diff --git a/src/EFCore/Metadata/IKey.cs b/src/EFCore/Metadata/IKey.cs index 198f464f5b7..789d00eb539 100644 --- a/src/EFCore/Metadata/IKey.cs +++ b/src/EFCore/Metadata/IKey.cs @@ -1,6 +1,7 @@ // 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.Collections.Generic; using System.Linq; using Microsoft.EntityFrameworkCore.ChangeTracking; @@ -25,6 +26,13 @@ public interface IKey : IReadOnlyKey, IAnnotatable /// new IEntityType DeclaringEntityType { get; } + /// + /// Returns the type of the key property for simple keys, or an object array for composite keys. + /// + /// The key type. + Type GetKeyType() + => Properties.Count > 1 ? typeof(object[]) : Properties.First().ClrType; + /// /// Gets all foreign keys that target a given primary or alternate key. /// diff --git a/src/EFCore/Metadata/IReadOnlyKey.cs b/src/EFCore/Metadata/IReadOnlyKey.cs index 1f3494b0f3e..f5ec05b7c4a 100644 --- a/src/EFCore/Metadata/IReadOnlyKey.cs +++ b/src/EFCore/Metadata/IReadOnlyKey.cs @@ -1,7 +1,6 @@ // 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.Collections.Generic; using System.Linq; using System.Text; @@ -26,13 +25,6 @@ public interface IReadOnlyKey : IReadOnlyAnnotatable /// IReadOnlyEntityType DeclaringEntityType { get; } - /// - /// Returns the type of the key property for simple keys, or an object array for composite keys. - /// - /// The key type. - Type GetKeyType() - => Properties.Count > 1 ? typeof(object[]) : Properties.First().ClrType; - /// /// Gets all foreign keys that target a given primary or alternate key. /// diff --git a/src/EFCore/Metadata/IReadOnlyProperty.cs b/src/EFCore/Metadata/IReadOnlyProperty.cs index ee6289794fa..7620f3077b2 100644 --- a/src/EFCore/Metadata/IReadOnlyProperty.cs +++ b/src/EFCore/Metadata/IReadOnlyProperty.cs @@ -65,7 +65,7 @@ CoreTypeMapping GetTypeMapping() } /// - /// Returns the for the given property. + /// Returns the type mapping for this property. /// /// The type mapping, or if none was found. CoreTypeMapping? FindTypeMapping(); diff --git a/src/EFCore/Metadata/Internal/ForeignKey.cs b/src/EFCore/Metadata/Internal/ForeignKey.cs index 170c0880beb..d020fdc8860 100644 --- a/src/EFCore/Metadata/Internal/ForeignKey.cs +++ b/src/EFCore/Metadata/Internal/ForeignKey.cs @@ -157,7 +157,7 @@ public virtual void SetRemovedFromModel() /// 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 SortedSet? ReferencingSkipNavigations { get; set; } + public virtual ISet? ReferencingSkipNavigations { get; set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/IRuntimeModel.cs b/src/EFCore/Metadata/Internal/IRuntimeModel.cs index 356e22d05fe..58a0debeaf2 100644 --- a/src/EFCore/Metadata/Internal/IRuntimeModel.cs +++ b/src/EFCore/Metadata/Internal/IRuntimeModel.cs @@ -18,5 +18,13 @@ public interface IRuntimeModel : IModel /// doing so can result in application failures when updating to a new Entity Framework Core release. /// bool SkipDetectChanges { 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. + /// + object? RelationalModel { get; } } } diff --git a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs index b5b6d9377e6..2735a25c682 100644 --- a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs @@ -109,7 +109,7 @@ public override InternalModelBuilder ModelBuilder { return configurationSource == ConfigurationSource.Explicit ? throw new InvalidOperationException(CoreStrings.ClashingNonSharedType(type.Name, clrType.ShortDisplayName())) - : (InternalEntityTypeBuilder?)null; + : null; } entityTypeSnapshot = InternalEntityTypeBuilder.DetachAllMembers(entityType); @@ -127,7 +127,7 @@ public override InternalModelBuilder ModelBuilder { return configurationSource == ConfigurationSource.Explicit ? throw new InvalidOperationException(CoreStrings.ClashingSharedType(clrType.ShortDisplayName())) - : (InternalEntityTypeBuilder?)null; + : null; } entityType = Metadata.FindEntityType(clrType); @@ -183,7 +183,7 @@ public override InternalModelBuilder ModelBuilder return configurationSource == ConfigurationSource.Explicit ? throw new InvalidOperationException( CoreStrings.ClashingMismatchedSharedType(type.Name, entityType.ClrType.ShortDisplayName())) - : (InternalEntityTypeBuilder?)null; + : null; } } diff --git a/src/EFCore/Metadata/SlimEntityType.cs b/src/EFCore/Metadata/RuntimeEntityType.cs similarity index 88% rename from src/EFCore/Metadata/SlimEntityType.cs rename to src/EFCore/Metadata/RuntimeEntityType.cs index bce53a8aa65..6fb93c7dac8 100644 --- a/src/EFCore/Metadata/SlimEntityType.cs +++ b/src/EFCore/Metadata/RuntimeEntityType.cs @@ -22,35 +22,35 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents an entity type in a model. /// - public class SlimEntityType : AnnotatableBase, IRuntimeEntityType + public class RuntimeEntityType : AnnotatableBase, IRuntimeEntityType { - private readonly List _foreignKeys = new(); + private readonly List _foreignKeys = new(); - private readonly SortedDictionary _navigations + private readonly SortedDictionary _navigations = new(StringComparer.Ordinal); - private readonly SortedDictionary _skipNavigations + private readonly SortedDictionary _skipNavigations = new(StringComparer.Ordinal); - private readonly SortedDictionary, SlimIndex> _unnamedIndexes + private readonly SortedDictionary, RuntimeIndex> _unnamedIndexes = new(PropertyListComparer.Instance); - private readonly SortedDictionary _namedIndexes + private readonly SortedDictionary _namedIndexes = new(StringComparer.Ordinal); - private readonly SortedDictionary _properties; + private readonly SortedDictionary _properties; - private readonly SortedDictionary, SlimKey> _keys + private readonly SortedDictionary, RuntimeKey> _keys = new(PropertyListComparer.Instance); - private readonly SortedDictionary _serviceProperties + private readonly SortedDictionary _serviceProperties = new(StringComparer.Ordinal); - private SlimKey? _primaryKey; + private RuntimeKey? _primaryKey; private readonly bool _hasSharedClrType; private readonly Type _clrType; - private readonly SlimEntityType? _baseType; - private readonly SortedSet _directlyDerivedTypes = new(EntityTypeFullNameComparer.Instance); + private readonly RuntimeEntityType? _baseType; + private readonly SortedSet _directlyDerivedTypes = new(EntityTypeFullNameComparer.Instance); private readonly ChangeTrackingStrategy _changeTrackingStrategy; private InstantiationBinding? _constructorBinding; private InstantiationBinding? _serviceOnlyConstructorBinding; @@ -77,12 +77,12 @@ private readonly SortedDictionary _servicePropertie /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimEntityType( + public RuntimeEntityType( string name, Type type, bool sharedClrType, - SlimModel model, - SlimEntityType? baseType, + RuntimeModel model, + RuntimeEntityType? baseType, string? discriminatorProperty, ChangeTrackingStrategy changeTrackingStrategy, PropertyInfo? indexerPropertyInfo, @@ -102,7 +102,7 @@ public SlimEntityType( _isPropertyBag = propertyBag; SetAnnotation(CoreAnnotationNames.DiscriminatorProperty, discriminatorProperty); - _properties = new SortedDictionary(new PropertyNameComparer(this)); + _properties = new SortedDictionary(new PropertyNameComparer(this)); } /// @@ -113,16 +113,16 @@ public SlimEntityType( /// /// Gets the model that this type belongs to. /// - public virtual SlimModel Model { [DebuggerStepThrough] get; } + public virtual RuntimeModel Model { [DebuggerStepThrough] get; } - private IEnumerable GetDerivedTypes() + private IEnumerable GetDerivedTypes() { if (_directlyDerivedTypes.Count == 0) { - return Enumerable.Empty(); + return Enumerable.Empty(); } - var derivedTypes = new List(); + var derivedTypes = new List(); var type = this; var currentTypeIndex = 0; while (type != null) @@ -137,14 +137,14 @@ private IEnumerable GetDerivedTypes() return derivedTypes; } - private SlimKey? FindPrimaryKey() + private RuntimeKey? FindPrimaryKey() => _baseType?.FindPrimaryKey() ?? _primaryKey; /// /// Sets the primary key for this entity type. /// /// The new primary key. - public virtual void SetPrimaryKey(SlimKey key) + public virtual void SetPrimaryKey(RuntimeKey key) { foreach (var property in key.Properties) { @@ -165,16 +165,16 @@ public virtual void SetPrimaryKey(SlimKey key) /// /// The properties that make up the alternate key. /// The newly created key. - public virtual SlimKey AddKey(IReadOnlyList properties) + public virtual RuntimeKey AddKey(IReadOnlyList properties) { - var key = new SlimKey(properties); + var key = new RuntimeKey(properties); _keys.Add(properties, key); foreach (var property in properties) { if (property.Keys == null) { - property.Keys = new List { key }; + property.Keys = new List { key }; } else { @@ -191,15 +191,15 @@ public virtual SlimKey AddKey(IReadOnlyList properties) /// /// The properties that make up the key. /// The key, or if none is defined. - public virtual SlimKey? FindKey(IReadOnlyList properties) + public virtual RuntimeKey? FindKey(IReadOnlyList properties) => _keys.TryGetValue(properties, out var key) ? key : _baseType?.FindKey(properties); - private IEnumerable GetDeclaredKeys() + private IEnumerable GetDeclaredKeys() => _keys.Values; - private IEnumerable GetKeys() + private IEnumerable GetKeys() => _baseType?.GetKeys().Concat(_keys.Values) ?? _keys.Values; /// @@ -221,17 +221,17 @@ private IEnumerable GetKeys() /// A value indicating whether the dependent entity is required. /// A value indicating whether this relationship defines an ownership. /// The newly created foreign key. - public virtual SlimForeignKey AddForeignKey( - IReadOnlyList properties, - SlimKey principalKey, - SlimEntityType principalEntityType, + public virtual RuntimeForeignKey AddForeignKey( + IReadOnlyList properties, + RuntimeKey principalKey, + RuntimeEntityType principalEntityType, DeleteBehavior deleteBehavior = ForeignKey.DefaultDeleteBehavior, bool unique = false, bool required = false, bool requiredDependent = false, bool ownership = false) { - var foreignKey = new SlimForeignKey( + var foreignKey = new RuntimeForeignKey( properties, principalKey, this, principalEntityType, deleteBehavior, unique, required, requiredDependent, ownership); _foreignKeys.Add(foreignKey); @@ -240,7 +240,7 @@ public virtual SlimForeignKey AddForeignKey( { if (property.ForeignKeys == null) { - property.ForeignKeys = new List { foreignKey }; + property.ForeignKeys = new List { foreignKey }; } else { @@ -250,7 +250,7 @@ public virtual SlimForeignKey AddForeignKey( if (principalKey.ReferencingForeignKeys == null) { - principalKey.ReferencingForeignKeys = new SortedSet(ForeignKeyComparer.Instance) { foreignKey }; + principalKey.ReferencingForeignKeys = new SortedSet(ForeignKeyComparer.Instance) { foreignKey }; } else { @@ -259,7 +259,7 @@ public virtual SlimForeignKey AddForeignKey( if (principalEntityType.DeclaredReferencingForeignKeys == null) { - principalEntityType.DeclaredReferencingForeignKeys = new SortedSet(ForeignKeyComparer.Instance) { foreignKey }; + principalEntityType.DeclaredReferencingForeignKeys = new SortedSet(ForeignKeyComparer.Instance) { foreignKey }; } else { @@ -269,26 +269,26 @@ public virtual SlimForeignKey AddForeignKey( return foreignKey; } - private IEnumerable FindForeignKeys(IReadOnlyList properties) + private IEnumerable FindForeignKeys(IReadOnlyList properties) => _baseType != null ? _foreignKeys.Count == 0 ? _baseType.FindForeignKeys(properties) : _baseType.FindForeignKeys(properties).Concat(FindDeclaredForeignKeys(properties)) : FindDeclaredForeignKeys(properties); - private SlimForeignKey? FindForeignKey( + private RuntimeForeignKey? FindForeignKey( IReadOnlyList properties, IReadOnlyKey principalKey, IReadOnlyEntityType principalEntityType) => FindDeclaredForeignKey(properties, principalKey, principalEntityType) ?? _baseType?.FindForeignKey(properties, principalKey, principalEntityType); - private IEnumerable GetDerivedForeignKeys() + private IEnumerable GetDerivedForeignKeys() => _directlyDerivedTypes.Count == 0 - ? Enumerable.Empty() + ? Enumerable.Empty() : GetDerivedTypes().SelectMany(et => et._foreignKeys); - private IEnumerable GetForeignKeys() + private IEnumerable GetForeignKeys() => _baseType != null ? _foreignKeys.Count == 0 ? _baseType.GetForeignKeys() @@ -300,12 +300,12 @@ private IEnumerable GetForeignKeys() /// /// The properties to find the foreign keys on. /// Declared foreign keys. - public virtual IEnumerable FindDeclaredForeignKeys(IReadOnlyList properties) + public virtual IEnumerable FindDeclaredForeignKeys(IReadOnlyList properties) => _foreignKeys.Count == 0 - ? Enumerable.Empty() + ? Enumerable.Empty() : _foreignKeys.Where(fk => PropertyListComparer.Instance.Equals(fk.Properties, properties)); - private SlimForeignKey? FindDeclaredForeignKey( + private RuntimeForeignKey? FindDeclaredForeignKey( IReadOnlyList properties, IReadOnlyKey principalKey, IReadOnlyEntityType principalEntityType) @@ -327,17 +327,17 @@ public virtual IEnumerable FindDeclaredForeignKeys(IReadOnlyList return null; } - private IEnumerable GetReferencingForeignKeys() + private IEnumerable GetReferencingForeignKeys() => _baseType != null ? (DeclaredReferencingForeignKeys?.Count ?? 0) == 0 ? _baseType.GetReferencingForeignKeys() : _baseType.GetReferencingForeignKeys().Concat(GetDeclaredReferencingForeignKeys()) : GetDeclaredReferencingForeignKeys(); - private IEnumerable GetDeclaredReferencingForeignKeys() - => DeclaredReferencingForeignKeys ?? Enumerable.Empty(); + private IEnumerable GetDeclaredReferencingForeignKeys() + => DeclaredReferencingForeignKeys ?? Enumerable.Empty(); - private SortedSet? DeclaredReferencingForeignKeys { get; set; } + private SortedSet? DeclaredReferencingForeignKeys { get; set; } /// /// Adds a new navigation property to this entity type. @@ -353,17 +353,17 @@ private IEnumerable GetDeclaredReferencingForeignKeys() /// The used for this navigation. /// A value indicating whether this navigation should be eager loaded by default. /// The newly created navigation property. - public virtual SlimNavigation AddNavigation( + public virtual RuntimeNavigation AddNavigation( string name, Type clrType, PropertyInfo? propertyInfo, FieldInfo? fieldInfo, - SlimForeignKey foreignKey, + RuntimeForeignKey foreignKey, bool onDependent, PropertyAccessMode propertyAccessMode = Internal.Model.DefaultPropertyAccessMode, bool eagerLoaded = false) { - var navigation = new SlimNavigation(name, clrType, propertyInfo, fieldInfo, foreignKey, propertyAccessMode, eagerLoaded); + var navigation = new RuntimeNavigation(name, clrType, propertyInfo, fieldInfo, foreignKey, propertyAccessMode, eagerLoaded); _navigations.Add(name, navigation); @@ -377,18 +377,18 @@ public virtual SlimNavigation AddNavigation( /// /// The name of the navigation property on the entity class. /// The navigation property, or if none is found. - public virtual SlimNavigation? FindNavigation(string name) - => (SlimNavigation?)((IReadOnlyEntityType)this).FindNavigation(name); + public virtual RuntimeNavigation? FindNavigation(string name) + => (RuntimeNavigation?)((IReadOnlyEntityType)this).FindNavigation(name); - private SlimNavigation? FindDeclaredNavigation(string name) + private RuntimeNavigation? FindDeclaredNavigation(string name) => _navigations.TryGetValue(name, out var navigation) ? navigation : null; - private IEnumerable GetDeclaredNavigations() + private IEnumerable GetDeclaredNavigations() => _navigations.Values; - private IEnumerable GetNavigations() + private IEnumerable GetNavigations() => _baseType != null ? _navigations.Count == 0 ? _baseType.GetNavigations() : _baseType.GetNavigations().Concat(_navigations.Values) : _navigations.Values; @@ -409,19 +409,19 @@ private IEnumerable GetNavigations() /// The used for this navigation. /// A value indicating whether this navigation should be eager loaded by default. /// The newly created skip navigation property. - public virtual SlimSkipNavigation AddSkipNavigation( + public virtual RuntimeSkipNavigation AddSkipNavigation( string name, Type clrType, PropertyInfo? propertyInfo, FieldInfo? fieldInfo, - SlimEntityType targetEntityType, - SlimForeignKey foreignKey, + RuntimeEntityType targetEntityType, + RuntimeForeignKey foreignKey, bool collection, bool onDependent, PropertyAccessMode propertyAccessMode = Internal.Model.DefaultPropertyAccessMode, bool eagerLoaded = false) { - var skipNavigation = new SlimSkipNavigation( + var skipNavigation = new RuntimeSkipNavigation( name, clrType, propertyInfo, @@ -444,26 +444,26 @@ public virtual SlimSkipNavigation AddSkipNavigation( /// /// The name of the navigation property on the entity class. /// The navigation property, or if none is found. - public virtual SlimSkipNavigation? FindSkipNavigation(string name) + public virtual RuntimeSkipNavigation? FindSkipNavigation(string name) => FindDeclaredSkipNavigation(name) ?? _baseType?.FindSkipNavigation(name); - private SlimSkipNavigation? FindSkipNavigation(MemberInfo memberInfo) + private RuntimeSkipNavigation? FindSkipNavigation(MemberInfo memberInfo) => FindSkipNavigation(memberInfo.GetSimpleMemberName()); - private SlimSkipNavigation? FindDeclaredSkipNavigation(string name) + private RuntimeSkipNavigation? FindDeclaredSkipNavigation(string name) => _skipNavigations.TryGetValue(name, out var navigation) ? navigation : null; - private IEnumerable GetDeclaredSkipNavigations() + private IEnumerable GetDeclaredSkipNavigations() => _skipNavigations.Values; - private IEnumerable GetDerivedSkipNavigations() + private IEnumerable GetDerivedSkipNavigations() => _directlyDerivedTypes.Count == 0 - ? Enumerable.Empty() + ? Enumerable.Empty() : GetDerivedTypes().SelectMany(et => et.GetDeclaredSkipNavigations()); - private IEnumerable GetSkipNavigations() + private IEnumerable GetSkipNavigations() => _baseType != null ? _skipNavigations.Count == 0 ? _baseType.GetSkipNavigations() @@ -477,12 +477,12 @@ private IEnumerable GetSkipNavigations() /// The name of the index. /// A value indicating whether the values assigned to the indexed properties are unique. /// The newly created index. - public virtual SlimIndex AddIndex( - IReadOnlyList properties, + public virtual RuntimeIndex AddIndex( + IReadOnlyList properties, string? name = null, bool unique = false) { - var index = new SlimIndex(properties, this, name, unique); + var index = new RuntimeIndex(properties, this, name, unique); if (name != null) { _namedIndexes.Add(name, index); @@ -496,7 +496,7 @@ public virtual SlimIndex AddIndex( { if (property.Indexes == null) { - property.Indexes = new List { index }; + property.Indexes = new List { index }; } else { @@ -517,7 +517,7 @@ public virtual SlimIndex AddIndex( /// /// The properties to find the index on. /// The index, or if none is found. - public virtual SlimIndex? FindIndex(IReadOnlyList properties) + public virtual RuntimeIndex? FindIndex(IReadOnlyList properties) => _unnamedIndexes.TryGetValue(properties, out var index) ? index : _baseType?.FindIndex(properties); @@ -527,22 +527,22 @@ public virtual SlimIndex AddIndex( /// /// The name of the index. /// The index, or if none is found. - public virtual SlimIndex? FindIndex(string name) + public virtual RuntimeIndex? FindIndex(string name) => _namedIndexes.TryGetValue(name, out var index) ? index : _baseType?.FindIndex(name); - private IEnumerable GetDeclaredIndexes() + private IEnumerable GetDeclaredIndexes() => _namedIndexes.Count == 0 ? _unnamedIndexes.Values : _unnamedIndexes.Values.Concat(_namedIndexes.Values); - private IEnumerable GetDerivedIndexes() + private IEnumerable GetDerivedIndexes() => _directlyDerivedTypes.Count == 0 - ? Enumerable.Empty() + ? Enumerable.Empty() : GetDerivedTypes().SelectMany(et => et.GetDeclaredIndexes()); - private IEnumerable GetIndexes() + private IEnumerable GetIndexes() => _baseType != null ? _namedIndexes.Count == 0 && _unnamedIndexes.Count == 0 ? _baseType.GetIndexes() @@ -579,7 +579,7 @@ private IEnumerable GetIndexes() /// The to use with keys for this property. /// The for this property. /// The newly created property. - public virtual SlimProperty AddProperty( + public virtual RuntimeProperty AddProperty( string name, Type propertyType, PropertyInfo? propertyInfo, @@ -601,7 +601,7 @@ public virtual SlimProperty AddProperty( ValueComparer? keyValueComparer = null, CoreTypeMapping? typeMapping = null) { - var property = new SlimProperty( + var property = new RuntimeProperty( name, propertyType, propertyInfo, @@ -640,20 +640,20 @@ public virtual SlimProperty AddProperty( /// /// The name of the property. /// The property, or if none is found. - public virtual SlimProperty? FindProperty(string name) + public virtual RuntimeProperty? FindProperty(string name) => FindDeclaredProperty(name) ?? _baseType?.FindProperty(name); - private SlimProperty? FindDeclaredProperty(string name) + private RuntimeProperty? FindDeclaredProperty(string name) => _properties.TryGetValue(name, out var property) ? property : null; - private IEnumerable GetDeclaredProperties() + private IEnumerable GetDeclaredProperties() => _properties.Values; - private IEnumerable GetDerivedProperties() + private IEnumerable GetDerivedProperties() => _directlyDerivedTypes.Count == 0 - ? Enumerable.Empty() + ? Enumerable.Empty() : GetDerivedTypes().SelectMany(et => et.GetDeclaredProperties()); /// @@ -666,9 +666,9 @@ private IEnumerable GetDerivedProperties() /// /// The property names. /// The properties, or if any property is not found. - public virtual IReadOnlyList? FindProperties(IEnumerable propertyNames) + public virtual IReadOnlyList? FindProperties(IEnumerable propertyNames) { - var properties = new List(); + var properties = new List(); foreach (var propertyName in propertyNames) { var property = FindProperty(propertyName); @@ -683,7 +683,7 @@ private IEnumerable GetDerivedProperties() return properties; } - private IEnumerable GetProperties() + private IEnumerable GetProperties() => _baseType != null ? _baseType.GetProperties().Concat(_properties.Values) : _properties.Values; @@ -696,13 +696,13 @@ private IEnumerable GetProperties() /// The corresponding CLR field or for a shadow property. /// The used for this property. /// The newly created service property. - public virtual SlimServiceProperty AddServiceProperty( + public virtual RuntimeServiceProperty AddServiceProperty( string name, PropertyInfo? propertyInfo, FieldInfo? fieldInfo, PropertyAccessMode propertyAccessMode = Internal.Model.DefaultPropertyAccessMode) { - var serviceProperty = new SlimServiceProperty( + var serviceProperty = new RuntimeServiceProperty( name, propertyInfo, fieldInfo, @@ -725,27 +725,27 @@ public virtual SlimServiceProperty AddServiceProperty( /// /// The name of the service property. /// The service property, or if none is found. - public virtual SlimServiceProperty? FindServiceProperty(string name) + public virtual RuntimeServiceProperty? FindServiceProperty(string name) => FindDeclaredServiceProperty(name) ?? _baseType?.FindServiceProperty(name); - private SlimServiceProperty? FindDeclaredServiceProperty(string name) + private RuntimeServiceProperty? FindDeclaredServiceProperty(string name) => _serviceProperties.TryGetValue(name, out var property) ? property : null; - private IEnumerable GetServiceProperties() + private IEnumerable GetServiceProperties() => _baseType != null ? _serviceProperties.Count == 0 ? _baseType.GetServiceProperties() : _baseType.GetServiceProperties().Concat(_serviceProperties.Values) : _serviceProperties.Values; - private IEnumerable GetDeclaredServiceProperties() + private IEnumerable GetDeclaredServiceProperties() => _serviceProperties.Values; - private IEnumerable GetDerivedServiceProperties() + private IEnumerable GetDerivedServiceProperties() => _directlyDerivedTypes.Count == 0 - ? Enumerable.Empty() + ? Enumerable.Empty() : GetDerivedTypes().SelectMany(et => et.GetDeclaredServiceProperties()); /// @@ -1049,7 +1049,7 @@ IEnumerable IEntityType.GetDeclaredNavigations() [DebuggerStepThrough] IEnumerable IReadOnlyEntityType.GetDerivedNavigations() => _directlyDerivedTypes.Count == 0 - ? Enumerable.Empty() + ? Enumerable.Empty() : GetDerivedTypes().SelectMany(et => et.GetDeclaredNavigations()); /// @@ -1340,6 +1340,6 @@ IEnumerable IEntityType.GetServiceProperties() => GetServiceProperties(); IEnumerable> IReadOnlyEntityType.GetSeedData(bool providerValues) - => throw new InvalidOperationException(CoreStrings.SlimModelMissingData); + => throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData); } } diff --git a/src/EFCore/Metadata/SlimForeignKey.cs b/src/EFCore/Metadata/RuntimeForeignKey.cs similarity index 91% rename from src/EFCore/Metadata/SlimForeignKey.cs rename to src/EFCore/Metadata/RuntimeForeignKey.cs index 90d21b6c781..87957a73744 100644 --- a/src/EFCore/Metadata/SlimForeignKey.cs +++ b/src/EFCore/Metadata/RuntimeForeignKey.cs @@ -17,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// Represents a relationship where a foreign key composed of properties on the dependent entity type /// references a corresponding primary or alternate key on the principal entity type. /// - public class SlimForeignKey : AnnotatableBase, IRuntimeForeignKey + public class RuntimeForeignKey : AnnotatableBase, IRuntimeForeignKey { private readonly DeleteBehavior _deleteBehavior; private readonly bool _isUnique; @@ -35,11 +35,11 @@ public class SlimForeignKey : AnnotatableBase, IRuntimeForeignKey /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimForeignKey( - IReadOnlyList dependentProperties, - SlimKey principalKey, - SlimEntityType dependentEntityType, - SlimEntityType principalEntityType, + public RuntimeForeignKey( + IReadOnlyList dependentProperties, + RuntimeKey principalKey, + RuntimeEntityType dependentEntityType, + RuntimeEntityType principalEntityType, DeleteBehavior deleteBehavior, bool unique, bool required, @@ -60,32 +60,32 @@ public SlimForeignKey( /// /// Gets the foreign key properties in the dependent entity. /// - public virtual IReadOnlyList Properties { get; } + public virtual IReadOnlyList Properties { get; } /// /// Gets the primary or alternate key that the relationship targets. /// - public virtual SlimKey PrincipalKey { get; } + public virtual RuntimeKey PrincipalKey { get; } /// /// Gets the dependent entity type. This may be different from the type that /// are defined on when the relationship is defined a derived type in an inheritance hierarchy (since the properties /// may be defined on a base type). /// - public virtual SlimEntityType DeclaringEntityType { get; } + public virtual RuntimeEntityType DeclaringEntityType { get; } /// /// Gets the principal entity type that this relationship targets. This may be different from the type that /// is defined on when the relationship targets a derived type in an inheritance /// hierarchy (since the key is defined on the base type of the hierarchy). /// - public virtual SlimEntityType PrincipalEntityType { get; } + public virtual RuntimeEntityType PrincipalEntityType { get; } [DisallowNull] - private SlimNavigation? DependentToPrincipal { get; set; } + private RuntimeNavigation? DependentToPrincipal { get; set; } [DisallowNull] - private SlimNavigation? PrincipalToDependent { get; set; } + private RuntimeNavigation? PrincipalToDependent { get; set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -95,7 +95,7 @@ public SlimForeignKey( /// [EntityFrameworkInternal] public virtual void AddNavigation( - SlimNavigation navigation, + RuntimeNavigation navigation, bool onDependent) { if (onDependent) @@ -115,7 +115,7 @@ public virtual void AddNavigation( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public virtual SortedSet? ReferencingSkipNavigations { get; set; } + public virtual SortedSet? ReferencingSkipNavigations { get; set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -258,7 +258,7 @@ bool IReadOnlyForeignKey.IsOwnership /// [DebuggerStepThrough] IEnumerable IReadOnlyForeignKey.GetReferencingSkipNavigations() - => ReferencingSkipNavigations ?? Enumerable.Empty(); + => ReferencingSkipNavigations ?? Enumerable.Empty(); /// [DebuggerStepThrough] diff --git a/src/EFCore/Metadata/SlimIndex.cs b/src/EFCore/Metadata/RuntimeIndex.cs similarity index 93% rename from src/EFCore/Metadata/SlimIndex.cs rename to src/EFCore/Metadata/RuntimeIndex.cs index 001a816c534..34debd820a9 100644 --- a/src/EFCore/Metadata/SlimIndex.cs +++ b/src/EFCore/Metadata/RuntimeIndex.cs @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents an index on a set of properties. /// - public class SlimIndex : AnnotatableBase, IIndex + public class RuntimeIndex : AnnotatableBase, IIndex { private readonly bool _isUnique; @@ -27,9 +27,9 @@ public class SlimIndex : AnnotatableBase, IIndex /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimIndex( - IReadOnlyList properties, - SlimEntityType declaringEntityType, + public RuntimeIndex( + IReadOnlyList properties, + RuntimeEntityType declaringEntityType, string? name, bool unique) { @@ -42,7 +42,7 @@ public SlimIndex( /// /// Gets the properties that this index is defined on. /// - public virtual IReadOnlyList Properties { get; } + public virtual IReadOnlyList Properties { get; } /// /// Gets the name of this index. @@ -54,7 +54,7 @@ public SlimIndex( /// are defined on when the index is defined a derived type in an inheritance hierarchy (since the properties /// may be defined on a base type). /// - public virtual SlimEntityType DeclaringEntityType { get; } + public virtual RuntimeEntityType DeclaringEntityType { get; } /// /// Returns a string that represents the current object. diff --git a/src/EFCore/Metadata/SlimKey.cs b/src/EFCore/Metadata/RuntimeKey.cs similarity index 94% rename from src/EFCore/Metadata/SlimKey.cs rename to src/EFCore/Metadata/RuntimeKey.cs index 361fdd76aea..d0c94364985 100644 --- a/src/EFCore/Metadata/SlimKey.cs +++ b/src/EFCore/Metadata/RuntimeKey.cs @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents a primary or alternate key on an entity type. /// - public class SlimKey : AnnotatableBase, IRuntimeKey + public class RuntimeKey : AnnotatableBase, IRuntimeKey { // Warning: Never access these fields directly as access needs to be thread-safe private Func? _identityMapFactory; @@ -29,7 +29,7 @@ public class SlimKey : AnnotatableBase, IRuntimeKey /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimKey(IReadOnlyList properties) + public RuntimeKey(IReadOnlyList properties) { Properties = properties; } @@ -37,14 +37,14 @@ public SlimKey(IReadOnlyList properties) /// /// Gets the properties that make up the key. /// - public virtual IReadOnlyList Properties { get; } + public virtual IReadOnlyList Properties { get; } /// /// Gets the entity type the key is defined on. This may be different from the type that /// are defined on when the key is defined a derived type in an inheritance hierarchy (since the properties /// may be defined on a base type). /// - public virtual SlimEntityType DeclaringEntityType + public virtual RuntimeEntityType DeclaringEntityType { [DebuggerStepThrough] get => Properties[0].DeclaringEntityType; @@ -57,7 +57,7 @@ public virtual SlimEntityType DeclaringEntityType /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public virtual ISet? ReferencingForeignKeys { get; set; } + public virtual ISet? ReferencingForeignKeys { get; set; } /// /// Returns a string that represents the current object. diff --git a/src/EFCore/Metadata/SlimModel.cs b/src/EFCore/Metadata/RuntimeModel.cs similarity index 88% rename from src/EFCore/Metadata/SlimModel.cs rename to src/EFCore/Metadata/RuntimeModel.cs index 793a1a08e82..9f714a1a127 100644 --- a/src/EFCore/Metadata/SlimModel.cs +++ b/src/EFCore/Metadata/RuntimeModel.cs @@ -25,12 +25,12 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// This is a light-weight implementation that is constructed from a built model and is not meant to be used at design-time. /// /// - public class SlimModel : AnnotatableBase, IRuntimeModel + public class RuntimeModel : AnnotatableBase, IRuntimeModel { - private readonly SortedDictionary _entityTypes = new(StringComparer.Ordinal); + private readonly SortedDictionary _entityTypes = new(StringComparer.Ordinal); private readonly ConcurrentDictionary _indexerPropertyInfoMap = new(); private readonly ConcurrentDictionary _clrTypeNameMap = new(); - private readonly Dictionary> _sharedTypes = new(); + private readonly Dictionary> _sharedTypes = new(); private readonly bool _skipDetectChanges; /// @@ -40,7 +40,7 @@ public class SlimModel : AnnotatableBase, IRuntimeModel /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimModel(RuntimeModelDependencies modelDependencies, bool skipDetectChanges = false) + public RuntimeModel(RuntimeModelDependencies modelDependencies, bool skipDetectChanges = false) { ((IModel)this).ModelDependencies = modelDependencies; _skipDetectChanges = skipDetectChanges; @@ -61,17 +61,17 @@ public SlimModel(RuntimeModelDependencies modelDependencies, bool skipDetectChan /// and a method that can be used to determine whether a given indexer property contains a value. /// /// The new entity type. - public virtual SlimEntityType AddEntityType( + public virtual RuntimeEntityType AddEntityType( string name, Type type, bool sharedClrType, - SlimEntityType? baseType = null, + RuntimeEntityType? baseType = null, string? discriminatorProperty = null, ChangeTrackingStrategy changeTrackingStrategy = ChangeTrackingStrategy.Snapshot, PropertyInfo? indexerPropertyInfo = null, bool propertyBag = false) { - var entityType = new SlimEntityType( + var entityType = new RuntimeEntityType( name, type, sharedClrType, @@ -90,7 +90,7 @@ public virtual SlimEntityType AddEntityType( } else { - var types = new SortedSet(EntityTypeFullNameComparer.Instance) { entityType }; + var types = new SortedSet(EntityTypeFullNameComparer.Instance) { entityType }; _sharedTypes.Add(type, types); } } @@ -107,25 +107,25 @@ public virtual SlimEntityType AddEntityType( /// /// The name of the entity type to find. /// The entity type, or if none is found. - public virtual SlimEntityType? FindEntityType(string name) + public virtual RuntimeEntityType? FindEntityType(string name) => _entityTypes.TryGetValue(name, out var entityType) ? entityType : null; - private SlimEntityType? FindEntityType(Type type) + private RuntimeEntityType? FindEntityType(Type type) => FindEntityType(GetDisplayName(type)); - private SlimEntityType? FindEntityType( + private RuntimeEntityType? FindEntityType( string name, string definingNavigationName, IReadOnlyEntityType definingEntityType) => FindEntityType(definingEntityType.GetOwnedName(name, definingNavigationName)); - private IEnumerable FindEntityTypes(Type type) + private IEnumerable FindEntityTypes(Type type) { var entityType = FindEntityType(GetDisplayName(type)); var result = entityType == null - ? Array.Empty() + ? Array.Empty() : new[] { entityType }; return _sharedTypes.TryGetValue(type, out var sharedTypes) @@ -145,8 +145,7 @@ private string GetDisplayName(Type type) /// 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. /// - [EntityFrameworkInternal] - public virtual object? RelationalModel + object? IRuntimeModel.RelationalModel => ((IAnnotatable)this).FindRuntimeAnnotationValue("Relational:RelationalModel"); /// @@ -171,12 +170,12 @@ bool IRuntimeModel.SkipDetectChanges /// [DebuggerStepThrough] PropertyAccessMode IReadOnlyModel.GetPropertyAccessMode() - => throw new InvalidOperationException(CoreStrings.SlimModelMissingData); + => throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData); /// [DebuggerStepThrough] ChangeTrackingStrategy IReadOnlyModel.GetChangeTrackingStrategy() - => throw new InvalidOperationException(CoreStrings.SlimModelMissingData); + => throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData); /// [DebuggerStepThrough] @@ -210,7 +209,7 @@ bool IModel.IsIndexerMethod(MethodInfo methodInfo) /// [DebuggerStepThrough] IReadOnlyEntityType? IReadOnlyModel.FindEntityType(string name, string definingNavigationName, IReadOnlyEntityType definingEntityType) - => FindEntityType(name, definingNavigationName, (SlimEntityType)definingEntityType); + => FindEntityType(name, definingNavigationName, (RuntimeEntityType)definingEntityType); /// [DebuggerStepThrough] @@ -218,7 +217,7 @@ bool IModel.IsIndexerMethod(MethodInfo methodInfo) string name, string definingNavigationName, IEntityType definingEntityType) - => FindEntityType(name, definingNavigationName, (SlimEntityType)definingEntityType); + => FindEntityType(name, definingNavigationName, (RuntimeEntityType)definingEntityType); /// [DebuggerStepThrough] diff --git a/src/EFCore/Metadata/SlimNavigation.cs b/src/EFCore/Metadata/RuntimeNavigation.cs similarity index 94% rename from src/EFCore/Metadata/SlimNavigation.cs rename to src/EFCore/Metadata/RuntimeNavigation.cs index f1cd5d4a543..7a5960ea2a3 100644 --- a/src/EFCore/Metadata/SlimNavigation.cs +++ b/src/EFCore/Metadata/RuntimeNavigation.cs @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents a navigation property which can be used to navigate a relationship. /// - public class SlimNavigation : SlimPropertyBase, INavigation + public class RuntimeNavigation : RuntimePropertyBase, INavigation { // Warning: Never access these fields directly as access needs to be thread-safe private IClrCollectionAccessor? _collectionAccessor; @@ -26,12 +26,12 @@ public class SlimNavigation : SlimPropertyBase, INavigation /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimNavigation( + public RuntimeNavigation( string name, Type clrType, PropertyInfo? propertyInfo, FieldInfo? fieldInfo, - SlimForeignKey foreignKey, + RuntimeForeignKey foreignKey, PropertyAccessMode propertyAccessMode, bool eagerLoaded) : base(name, propertyInfo, fieldInfo, propertyAccessMode) @@ -52,12 +52,12 @@ public SlimNavigation( /// /// Gets the foreign key that defines the relationship this navigation property will navigate. /// - public virtual SlimForeignKey ForeignKey { get; } + public virtual RuntimeForeignKey ForeignKey { get; } /// /// Gets the entity type that this navigation property belongs to. /// - public override SlimEntityType DeclaringEntityType + public override RuntimeEntityType DeclaringEntityType { [DebuggerStepThrough] get => ((IReadOnlyNavigation)this).IsOnDependent ? ForeignKey.DeclaringEntityType : ForeignKey.PrincipalEntityType; diff --git a/src/EFCore/Metadata/SlimProperty.cs b/src/EFCore/Metadata/RuntimeProperty.cs similarity index 93% rename from src/EFCore/Metadata/SlimProperty.cs rename to src/EFCore/Metadata/RuntimeProperty.cs index dad86d3f55c..8581ab9abb0 100644 --- a/src/EFCore/Metadata/SlimProperty.cs +++ b/src/EFCore/Metadata/RuntimeProperty.cs @@ -19,7 +19,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Represents a scalar property of an entity type. /// - public class SlimProperty : SlimPropertyBase, IProperty + public class RuntimeProperty : RuntimePropertyBase, IProperty { private readonly bool _isNullable; private readonly ValueGenerated _valueGenerated; @@ -39,12 +39,12 @@ public class SlimProperty : SlimPropertyBase, IProperty /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimProperty( + public RuntimeProperty( string name, Type clrType, PropertyInfo? propertyInfo, FieldInfo? fieldInfo, - SlimEntityType declaringEntityType, + RuntimeEntityType declaringEntityType, PropertyAccessMode propertyAccessMode, bool nullable, bool concurrencyToken, @@ -107,7 +107,7 @@ public SlimProperty( /// /// Gets the type that this property belongs to. /// - public override SlimEntityType DeclaringEntityType { get; } + public override RuntimeEntityType DeclaringEntityType { get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -116,7 +116,7 @@ public SlimProperty( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public virtual SlimKey? PrimaryKey { get; set; } + public virtual RuntimeKey? PrimaryKey { get; set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -125,10 +125,10 @@ public SlimProperty( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public virtual List? Keys { get; set; } + public virtual List? Keys { get; set; } - private IEnumerable GetContainingKeys() - => Keys ?? Enumerable.Empty(); + private IEnumerable GetContainingKeys() + => Keys ?? Enumerable.Empty(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -137,10 +137,10 @@ private IEnumerable GetContainingKeys() /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public virtual List? ForeignKeys { get; set; } + public virtual List? ForeignKeys { get; set; } - private IEnumerable GetContainingForeignKeys() - => ForeignKeys ?? Enumerable.Empty(); + private IEnumerable GetContainingForeignKeys() + => ForeignKeys ?? Enumerable.Empty(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -149,10 +149,10 @@ private IEnumerable GetContainingForeignKeys() /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public virtual List? Indexes { get; set; } + public virtual List? Indexes { get; set; } - private IEnumerable GetContainingIndexes() - => Indexes ?? Enumerable.Empty(); + private IEnumerable GetContainingIndexes() + => Indexes ?? Enumerable.Empty(); private CoreTypeMapping TypeMapping => NonCapturingLazyInitializer.EnsureInitialized( diff --git a/src/EFCore/Metadata/SlimPropertyBase.cs b/src/EFCore/Metadata/RuntimePropertyBase.cs similarity index 96% rename from src/EFCore/Metadata/SlimPropertyBase.cs rename to src/EFCore/Metadata/RuntimePropertyBase.cs index 51e6b9fd8bb..260ea4c99d0 100644 --- a/src/EFCore/Metadata/SlimPropertyBase.cs +++ b/src/EFCore/Metadata/RuntimePropertyBase.cs @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// /// Base type for navigations and properties. /// - public abstract class SlimPropertyBase : AnnotatableBase, IRuntimePropertyBase + public abstract class RuntimePropertyBase : AnnotatableBase, IRuntimePropertyBase { private readonly PropertyInfo? _propertyInfo; private readonly FieldInfo? _fieldInfo; @@ -37,7 +37,7 @@ public abstract class SlimPropertyBase : AnnotatableBase, IRuntimePropertyBase /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected SlimPropertyBase( + protected RuntimePropertyBase( string name, PropertyInfo? propertyInfo, FieldInfo? fieldInfo, @@ -57,7 +57,7 @@ protected SlimPropertyBase( /// /// Gets the type that this property-like object belongs to. /// - public abstract SlimEntityType DeclaringEntityType { get; } + public abstract RuntimeEntityType DeclaringEntityType { get; } /// /// Gets the type of value that this property-like object holds. diff --git a/src/EFCore/Metadata/SlimServiceProperty.cs b/src/EFCore/Metadata/RuntimeServiceProperty.cs similarity index 94% rename from src/EFCore/Metadata/SlimServiceProperty.cs rename to src/EFCore/Metadata/RuntimeServiceProperty.cs index d889f47f41b..4bfb62205b5 100644 --- a/src/EFCore/Metadata/SlimServiceProperty.cs +++ b/src/EFCore/Metadata/RuntimeServiceProperty.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// Represents a property on an entity type that represents an /// injected service from the . /// - public class SlimServiceProperty : SlimPropertyBase, IServiceProperty + public class RuntimeServiceProperty : RuntimePropertyBase, IServiceProperty { private ServiceParameterBinding? _parameterBinding; @@ -26,11 +26,11 @@ public class SlimServiceProperty : SlimPropertyBase, IServiceProperty /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimServiceProperty( + public RuntimeServiceProperty( string name, PropertyInfo? propertyInfo, FieldInfo? fieldInfo, - SlimEntityType declaringEntityType, + RuntimeEntityType declaringEntityType, PropertyAccessMode propertyAccessMode) : base(name, propertyInfo, fieldInfo, propertyAccessMode) { @@ -43,7 +43,7 @@ public SlimServiceProperty( /// /// Gets the type that this property-like object belongs to. /// - public override SlimEntityType DeclaringEntityType { get; } + public override RuntimeEntityType DeclaringEntityType { get; } /// /// Gets the type of value that this property-like object holds. diff --git a/src/EFCore/Metadata/SlimSkipNavigation.cs b/src/EFCore/Metadata/RuntimeSkipNavigation.cs similarity index 91% rename from src/EFCore/Metadata/SlimSkipNavigation.cs rename to src/EFCore/Metadata/RuntimeSkipNavigation.cs index 2801d44944d..403a1edb636 100644 --- a/src/EFCore/Metadata/SlimSkipNavigation.cs +++ b/src/EFCore/Metadata/RuntimeSkipNavigation.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// Represents a navigation property that is part of a relationship /// that is forwarded through a third entity type. /// - public class SlimSkipNavigation : SlimPropertyBase, IRuntimeSkipNavigation + public class RuntimeSkipNavigation : RuntimePropertyBase, IRuntimeSkipNavigation { - private readonly SlimForeignKey _foreignKey; + private readonly RuntimeForeignKey _foreignKey; private readonly bool _isOnDependent; private readonly bool _isCollection; @@ -34,14 +34,14 @@ public class SlimSkipNavigation : SlimPropertyBase, IRuntimeSkipNavigation /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public SlimSkipNavigation( + public RuntimeSkipNavigation( string name, Type clrType, PropertyInfo? propertyInfo, FieldInfo? fieldInfo, - SlimEntityType declaringEntityType, - SlimEntityType targetEntityType, - SlimForeignKey foreignKey, + RuntimeEntityType declaringEntityType, + RuntimeEntityType targetEntityType, + RuntimeForeignKey foreignKey, bool collection, bool onDependent, PropertyAccessMode propertyAccessMode, @@ -54,7 +54,7 @@ public SlimSkipNavigation( _foreignKey = foreignKey; if (foreignKey.ReferencingSkipNavigations == null) { - foreignKey.ReferencingSkipNavigations = new SortedSet(SkipNavigationComparer.Instance) { this }; + foreignKey.ReferencingSkipNavigations = new SortedSet(SkipNavigationComparer.Instance) { this }; } else { @@ -77,18 +77,18 @@ public SlimSkipNavigation( /// /// Gets the type that this property belongs to. /// - public override SlimEntityType DeclaringEntityType { get; } + public override RuntimeEntityType DeclaringEntityType { get; } /// /// Gets the entity type that this navigation property will hold an instance(s) of. /// - public virtual SlimEntityType TargetEntityType { get; } + public virtual RuntimeEntityType TargetEntityType { get; } /// /// Gets or sets the inverse navigation. /// [DisallowNull] - public virtual SlimSkipNavigation? Inverse { get; set; } + public virtual RuntimeSkipNavigation? Inverse { get; set; } /// /// Returns a string that represents the current object. diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index eb8486677bb..e56ce6d0e83 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -2340,6 +2340,12 @@ public static string RetryLimitExceeded(object? retryLimit, object? strategy) GetString("RetryLimitExceeded", nameof(retryLimit), nameof(strategy)), retryLimit, strategy); + /// + /// The requested configuration is not stored in the read-optimized model, please use 'DbContext.GetService<IDesignTimeModel>().Model'. + /// + public static string RuntimeModelMissingData + => GetString("RuntimeModelMissingData"); + /// /// While registering a runtime parameter, the lambda expression must have only one parameter which must be same as 'QueryCompilationContext.QueryContextParameter' expression. /// @@ -2609,12 +2615,6 @@ public static string SkipNavigationWrongType(object? navigation, object? entityT GetString("SkipNavigationWrongType", nameof(navigation), nameof(entityType), nameof(otherEntityType)), navigation, entityType, otherEntityType); - /// - /// The requested configuration is not stored in the read-optimized model, please use 'DbContext.DesignTimeModel'. - /// - public static string SlimModelMissingData - => GetString("SlimModelMissingData"); - /// /// The property '{1_entityType}.{0_property}' cannot be assigned a value generated by the database. Store-generated values can only be assigned to properties configured to use store-generated values. /// diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 9dca24d9622..2023e55ea9e 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -1323,6 +1323,9 @@ The maximum number of retries ({retryLimit}) was exceeded while executing database operations with '{strategy}'. See the inner exception for the most recent failure. + + The requested configuration is not stored in the read-optimized model, please use 'DbContext.GetService&lt;IDesignTimeModel&gt;().Model'. + While registering a runtime parameter, the lambda expression must have only one parameter which must be same as 'QueryCompilationContext.QueryContextParameter' expression. @@ -1429,9 +1432,6 @@ The skip navigation '{navigation}' cannot be removed from the entity type '{entityType}' because it is defined on the entity type '{otherEntityType}'. - - The requested configuration is not stored in the read-optimized model, please use 'DbContext.DesignTimeModel'. - The property '{1_entityType}.{0_property}' cannot be assigned a value generated by the database. Store-generated values can only be assigned to properties configured to use store-generated values.