From 13bf9abb7ffafa11a3949ff7837e215eba1b9265 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Thu, 1 Aug 2024 12:46:42 +0100 Subject: [PATCH 1/2] Change default embedded discriminator property from "Discriminator" to "$type" Fixes #34269 Use the following to revert back to the old behavior: ```C# modelBuilder.HasEmbeddedDiscriminatorName("Discriminator"); ``` --- .../CosmosDiscriminatorConvention.cs | 25 +- .../Builders/IConventionModelBuilder.cs | 16 + .../Metadata/Conventions/ConventionSet.cs | 21 + .../Conventions/DiscriminatorConvention.cs | 2 +- ...odelEmbeddedDiscriminatorNameConvention.cs | 26 + .../ConventionDispatcher.ConventionScope.cs | 5 + ...entionDispatcher.DelayedConventionScope.cs | 892 ++++++------------ ...tionDispatcher.ImmediateConventionScope.cs | 29 + .../Internal/ConventionDispatcher.cs | 6 + src/EFCore/Metadata/IConventionModel.cs | 14 + src/EFCore/Metadata/IMutableModel.cs | 6 + src/EFCore/Metadata/IReadOnlyModel.cs | 7 + .../Metadata/Internal/CoreAnnotationNames.cs | 9 + .../Metadata/Internal/InternalModelBuilder.cs | 50 + src/EFCore/Metadata/Internal/Model.cs | 63 ++ src/EFCore/Metadata/RuntimeModel.cs | 5 + src/EFCore/ModelBuilder.cs | 16 +- .../Query/StructuralTypeShaperExpression.cs | 4 +- .../BuiltInDataTypesCosmosTest.cs | 2 +- .../CustomConvertersCosmosTest.cs | 8 +- .../EmbeddedDocumentsTest.cs | 2 +- .../Query/FromSqlQueryCosmosTest.cs | 92 +- .../Query/InheritanceQueryCosmosFixture.cs | 1 + .../Query/InheritanceQueryCosmosTest.cs | 24 +- ...aredPrimitiveCollectionsQueryCosmosTest.cs | 2 +- ...thwindAggregateOperatorsQueryCosmosTest.cs | 98 +- .../NorthwindDbFunctionsQueryCosmosTest.cs | 4 +- .../NorthwindFunctionsQueryCosmosTest.cs | 66 +- ...NorthwindKeylessEntitiesQueryCosmosTest.cs | 4 +- .../NorthwindMiscellaneousQueryCosmosTest.cs | 94 +- .../Query/NorthwindQueryCosmosFixture.cs | 10 +- .../Query/NorthwindSelectQueryCosmosTest.cs | 76 +- .../Query/NorthwindWhereQueryCosmosTest.cs | 110 +-- .../Query/OwnedQueryCosmosTest.cs | 114 +-- .../PrimitiveCollectionsQueryCosmosTest.cs | 2 +- ...mPartitionKeyQueryDiscriminatorInIdTest.cs | 122 +-- ...temPartitionKeyQueryInheritanceTestBase.cs | 6 +- ...artitionKeyQueryNoDiscriminatorInIdTest.cs | 74 +- ...titionKeyQueryRootDiscriminatorInIdTest.cs | 72 +- .../Query/ReadItemPartitionKeyQueryTest.cs | 18 +- .../ReadItemPartitionKeyQueryTestBase.cs | 6 +- .../ReloadTest.cs | 2 +- .../Baselines/BigModel/ManyTypesEntityType.cs | 282 +++--- .../BigModel/PrincipalBaseEntityType.cs | 22 +- ...cipalDerivedDependentBasebyteEntityType.cs | 42 +- .../BigModel/PrincipalDerivedEntityType.cs | 8 +- .../ComplexTypes/PrincipalBaseEntityType.cs | 22 +- .../PrincipalDerivedEntityType.cs | 8 +- .../SimpleModel/DependentDerivedEntityType.cs | 76 +- .../TestUtilities/CosmosModelAsserter.cs | 4 +- .../CosmosNorthwindTestStoreFactory.cs | 2 +- .../TestUtilities/CosmosTestStore.cs | 7 +- .../Extensions/CosmosBuilderExtensionsTest.cs | 4 +- .../ModelBuilding/ModelBuilderTest.cs | 7 + .../TestUtilities/TestHelpers.cs | 1 + 55 files changed, 1362 insertions(+), 1328 deletions(-) create mode 100644 src/EFCore/Metadata/Conventions/IModelEmbeddedDiscriminatorNameConvention.cs diff --git a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs index 83ce68b595b..d761853a232 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Metadata.Internal; // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions; @@ -19,7 +18,8 @@ public class CosmosDiscriminatorConvention : IForeignKeyOwnershipChangedConvention, IForeignKeyRemovedConvention, IEntityTypeAddedConvention, - IEntityTypeAnnotationChangedConvention + IEntityTypeAnnotationChangedConvention, + IModelEmbeddedDiscriminatorNameConvention { /// /// Creates a new instance of . @@ -86,7 +86,7 @@ private static void ProcessEntityType(IConventionEntityTypeBuilder entityTypeBui if (entityType.IsDocumentRoot()) { - entityTypeBuilder.HasDiscriminator(typeof(string)) + entityTypeBuilder.HasDiscriminator(entityType.Model.GetEmbeddedDiscriminatorName(), typeof(string)) ?.HasValue(entityType, entityType.ShortName()); } else @@ -125,7 +125,7 @@ public override void ProcessEntityTypeBaseTypeChanged( { if (entityType.IsDocumentRoot()) { - entityTypeBuilder.HasDiscriminator(typeof(string)); + entityTypeBuilder.HasDiscriminator(entityType.Model.GetEmbeddedDiscriminatorName(), typeof(string)); } } else @@ -137,7 +137,7 @@ public override void ProcessEntityTypeBaseTypeChanged( return; } - var discriminator = rootType.Builder.HasDiscriminator(typeof(string)); + var discriminator = rootType.Builder.HasDiscriminator(entityType.Model.GetEmbeddedDiscriminatorName(), typeof(string)); if (discriminator != null) { SetDefaultDiscriminatorValues(entityTypeBuilder.Metadata.GetDerivedTypesInclusive(), discriminator); @@ -163,4 +163,19 @@ public override void ProcessEntityTypeRemoved( IConventionContext context) { } + + /// + public void ProcessEmbeddedDiscriminatorName( + IConventionModelBuilder modelBuilder, string? oldName, string? newName, IConventionContext context) + { + if (oldName == newName) + { + return; + } + + foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) + { + ProcessEntityType(entityType.Builder); + } + } } diff --git a/src/EFCore/Metadata/Builders/IConventionModelBuilder.cs b/src/EFCore/Metadata/Builders/IConventionModelBuilder.cs index 280a885ce85..4a7bd139666 100644 --- a/src/EFCore/Metadata/Builders/IConventionModelBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionModelBuilder.cs @@ -341,4 +341,20 @@ bool CanHaveSharedTypeEntity( /// Indicates whether the configuration was specified using a data annotation. /// if the given property access mode can be set. bool CanSetPropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); + + /// + /// Sets the name to use for discriminator properties embedded in JSON documents. The default is "$type". + /// + /// The property name, or to clear the name set. + /// Indicates whether the configuration was specified using a data annotation. + /// The same builder instance if the configuration was successful, otherwise. + IConventionModelBuilder? HasEmbeddedDiscriminatorName(string? name, bool fromDataAnnotation = false); + + /// + /// Returns a value indicating whether the given name can be set from the current configuration source + /// + /// The property name, or to clear the name set. + /// Indicates whether the configuration was specified using a data annotation. + /// if the given property access mode can be set. + bool CanSetEmbeddedDiscriminatorName(string? name, bool fromDataAnnotation = false); } diff --git a/src/EFCore/Metadata/Conventions/ConventionSet.cs b/src/EFCore/Metadata/Conventions/ConventionSet.cs index 7ada55d5232..ac573c61de1 100644 --- a/src/EFCore/Metadata/Conventions/ConventionSet.cs +++ b/src/EFCore/Metadata/Conventions/ConventionSet.cs @@ -31,6 +31,11 @@ public class ConventionSet /// public virtual List ModelAnnotationChangedConventions { get; } = []; + /// + /// Conventions to run when an annotation is set or removed on an entity type. + /// + public virtual List ModelEmbeddedDiscriminatorNameConventions { get; } = []; + /// /// Conventions to run when a type is ignored. /// @@ -321,6 +326,12 @@ public virtual void Replace(TImplementation newConvention) ModelAnnotationChangedConventions.Add(modelAnnotationChangedConvention); } + if (newConvention is IModelEmbeddedDiscriminatorNameConvention modelEmbeddedDiscriminatorNameConvention + && !Replace(ModelEmbeddedDiscriminatorNameConventions, modelEmbeddedDiscriminatorNameConvention, oldConventionType)) + { + ModelEmbeddedDiscriminatorNameConventions.Add(modelEmbeddedDiscriminatorNameConvention); + } + if (newConvention is ITypeIgnoredConvention typeIgnoredConvention && !Replace(TypeIgnoredConventions, typeIgnoredConvention, oldConventionType)) { @@ -696,6 +707,11 @@ public virtual void Add(IConvention convention) ModelAnnotationChangedConventions.Add(modelAnnotationChangedConvention); } + if (convention is IModelEmbeddedDiscriminatorNameConvention modelEmbeddedDiscriminatorNameConvention) + { + ModelEmbeddedDiscriminatorNameConventions.Add(modelEmbeddedDiscriminatorNameConvention); + } + if (convention is ITypeIgnoredConvention typeIgnoredConvention) { TypeIgnoredConventions.Add(typeIgnoredConvention); @@ -1034,6 +1050,11 @@ public virtual void Remove(Type conventionType) Remove(ModelAnnotationChangedConventions, conventionType); } + if (typeof(IModelEmbeddedDiscriminatorNameConvention).IsAssignableFrom(conventionType)) + { + Remove(ModelEmbeddedDiscriminatorNameConventions, conventionType); + } + if (typeof(ITypeIgnoredConvention).IsAssignableFrom(conventionType)) { Remove(TypeIgnoredConventions, conventionType); diff --git a/src/EFCore/Metadata/Conventions/DiscriminatorConvention.cs b/src/EFCore/Metadata/Conventions/DiscriminatorConvention.cs index 0ec54cfe42e..3abe5c2a6b5 100644 --- a/src/EFCore/Metadata/Conventions/DiscriminatorConvention.cs +++ b/src/EFCore/Metadata/Conventions/DiscriminatorConvention.cs @@ -86,7 +86,7 @@ public virtual void ProcessDiscriminatorPropertySet( return; } - var discriminator = entityTypeBuilder.HasDiscriminator(typeof(string)); + var discriminator = entityTypeBuilder.HasDiscriminator(name, typeof(string)); if (discriminator != null) { SetDefaultDiscriminatorValues(entityTypeBuilder.Metadata.GetDerivedTypesInclusive(), discriminator); diff --git a/src/EFCore/Metadata/Conventions/IModelEmbeddedDiscriminatorNameConvention.cs b/src/EFCore/Metadata/Conventions/IModelEmbeddedDiscriminatorNameConvention.cs new file mode 100644 index 00000000000..6b8c7b74228 --- /dev/null +++ b/src/EFCore/Metadata/Conventions/IModelEmbeddedDiscriminatorNameConvention.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.Metadata.Conventions; + +/// +/// Represents an operation that should be performed when the embedded discriminator name for the model changes. +/// +/// +/// See Model building conventions for more information and examples. +/// +public interface IModelEmbeddedDiscriminatorNameConvention : IConvention +{ + /// + /// Called after has been called. + /// + /// The builder for the model. + /// The current discriminator name. + /// The new discriminator name. + /// Additional information associated with convention execution. + void ProcessEmbeddedDiscriminatorName( + IConventionModelBuilder modelBuilder, + string? oldName, + string? newName, + IConventionContext context); +} diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs index 36bed6b4497..6ccb4600a06 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs @@ -182,6 +182,11 @@ public int GetLeafCount() IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation); + public abstract string? OnModelEmbeddedDiscriminatorNameChanged( + IConventionModelBuilder modelBuilder, + string? oldName, + string? newName); + public abstract IConventionNavigationBuilder? OnNavigationAdded(IConventionNavigationBuilder navigationBuilder); public abstract string? OnNavigationRemoved( diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs index 761f9f4e859..e0a7200e49b 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs @@ -5,39 +5,31 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; public partial class ConventionDispatcher { - private sealed class DelayedConventionScope : ConventionScope + private sealed class DelayedConventionScope(ConventionScope parent, List? children = null) : ConventionScope { - private List? _children; - - public DelayedConventionScope(ConventionScope parent, List? children = null) - { - Parent = parent; - _children = children; - } - - public override ConventionScope Parent { [DebuggerStepThrough] get; } + public override ConventionScope Parent { [DebuggerStepThrough] get; } = parent; public override IReadOnlyList? Children { [DebuggerStepThrough] - get => _children; + get => children; } private void Add(ConventionNode node) { - _children ??= []; + children ??= []; - _children.Add(node); + children.Add(node); } public override void Run(ConventionDispatcher dispatcher) { - if (_children == null) + if (children == null) { return; } - foreach (var conventionNode in _children) + foreach (var conventionNode in children) { conventionNode.Run(dispatcher); } @@ -53,6 +45,12 @@ public override void Run(ConventionDispatcher dispatcher) return annotation; } + public override string? OnModelEmbeddedDiscriminatorNameChanged(IConventionModelBuilder modelBuilder, string? oldName, string? newName) + { + Add(new OnModelEmbeddedDiscriminatorNameChangedNode(modelBuilder, oldName, newName)); + return newName; + } + public override string OnTypeIgnored(IConventionModelBuilder modelBuilder, string name, Type? type) { Add(new OnTypeIgnoredNode(modelBuilder, name, type)); @@ -454,902 +452,620 @@ public override IConventionProperty OnPropertyRemoved( } } - private sealed class OnModelAnnotationChangedNode : ConventionNode + private sealed class OnModelAnnotationChangedNode( + IConventionModelBuilder modelBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnModelAnnotationChangedNode( - IConventionModelBuilder modelBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - ModelBuilder = modelBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionModelBuilder ModelBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionModelBuilder ModelBuilder { get; } = modelBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnModelAnnotationChanged( ModelBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnTypeIgnoredNode : ConventionNode + private sealed class OnModelEmbeddedDiscriminatorNameChangedNode( + IConventionModelBuilder modelBuilder, + string? oldName, + string? newName) + : ConventionNode { - public OnTypeIgnoredNode(IConventionModelBuilder modelBuilder, string name, Type? type) - { - ModelBuilder = modelBuilder; - Name = name; - Type = type; - } + public IConventionModelBuilder ModelBuilder { get; } = modelBuilder; + public string? OldName { get; } = oldName; + public string? NewName { get; } = newName; + + public override void Run(ConventionDispatcher dispatcher) + => dispatcher._immediateConventionScope.OnModelEmbeddedDiscriminatorNameChanged(ModelBuilder, OldName, NewName); + } - public IConventionModelBuilder ModelBuilder { get; } - public string Name { get; } - public Type? Type { get; } + private sealed class OnTypeIgnoredNode(IConventionModelBuilder modelBuilder, string name, Type? type) : ConventionNode + { + public IConventionModelBuilder ModelBuilder { get; } = modelBuilder; + public string Name { get; } = name; + public Type? Type { get; } = type; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnTypeIgnored(ModelBuilder, Name, Type); } - private sealed class OnEntityTypeAddedNode : ConventionNode + private sealed class OnEntityTypeAddedNode(IConventionEntityTypeBuilder entityTypeBuilder) : ConventionNode { - public OnEntityTypeAddedNode(IConventionEntityTypeBuilder entityTypeBuilder) - { - EntityTypeBuilder = entityTypeBuilder; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypeAdded(EntityTypeBuilder); } - private sealed class OnEntityTypeRemovedNode : ConventionNode + private sealed class OnEntityTypeRemovedNode(IConventionModelBuilder modelBuilder, IConventionEntityType entityType) + : ConventionNode { - public OnEntityTypeRemovedNode(IConventionModelBuilder modelBuilder, IConventionEntityType entityType) - { - ModelBuilder = modelBuilder; - EntityType = entityType; - } - - public IConventionModelBuilder ModelBuilder { get; } - public IConventionEntityType EntityType { get; } + public IConventionModelBuilder ModelBuilder { get; } = modelBuilder; + public IConventionEntityType EntityType { get; } = entityType; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypeRemoved(ModelBuilder, EntityType); } - private sealed class OnEntityTypeMemberIgnoredNode : ConventionNode + private sealed class OnEntityTypeMemberIgnoredNode(IConventionEntityTypeBuilder entityTypeBuilder, string name) : ConventionNode { - public OnEntityTypeMemberIgnoredNode(IConventionEntityTypeBuilder entityTypeBuilder, string name) - { - EntityTypeBuilder = entityTypeBuilder; - Name = name; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public string Name { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public string Name { get; } = name; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypeMemberIgnored(EntityTypeBuilder, Name); } - private sealed class OnDiscriminatorPropertySetNode : ConventionNode + private sealed class OnDiscriminatorPropertySetNode(IConventionEntityTypeBuilder entityTypeBuilder, string? name) : ConventionNode { - public OnDiscriminatorPropertySetNode(IConventionEntityTypeBuilder entityTypeBuilder, string? name) - { - EntityTypeBuilder = entityTypeBuilder; - Name = name; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public string? Name { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public string? Name { get; } = name; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnDiscriminatorPropertySet(EntityTypeBuilder, Name); } - private sealed class OnEntityTypeBaseTypeChangedNode : ConventionNode + private sealed class OnEntityTypeBaseTypeChangedNode( + IConventionEntityTypeBuilder entityTypeBuilder, + IConventionEntityType? newBaseType, + IConventionEntityType? previousBaseType) + : ConventionNode { - public OnEntityTypeBaseTypeChangedNode( - IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType? newBaseType, - IConventionEntityType? previousBaseType) - { - EntityTypeBuilder = entityTypeBuilder; - NewBaseType = newBaseType; - PreviousBaseType = previousBaseType; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionEntityType? NewBaseType { get; } - public IConventionEntityType? PreviousBaseType { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public IConventionEntityType? NewBaseType { get; } = newBaseType; + public IConventionEntityType? PreviousBaseType { get; } = previousBaseType; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypeBaseTypeChanged( EntityTypeBuilder, NewBaseType, PreviousBaseType); } - private sealed class OnEntityTypeAnnotationChangedNode : ConventionNode + private sealed class OnEntityTypeAnnotationChangedNode( + IConventionEntityTypeBuilder entityTypeBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnEntityTypeAnnotationChangedNode( - IConventionEntityTypeBuilder entityTypeBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - EntityTypeBuilder = entityTypeBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypeAnnotationChanged( EntityTypeBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnComplexTypeMemberIgnoredNode : ConventionNode + private sealed class OnComplexTypeMemberIgnoredNode(IConventionComplexTypeBuilder complexTypeBuilder, string name) : ConventionNode { - public OnComplexTypeMemberIgnoredNode(IConventionComplexTypeBuilder complexTypeBuilder, string name) - { - ComplexTypeBuilder = complexTypeBuilder; - Name = name; - } - - public IConventionComplexTypeBuilder ComplexTypeBuilder { get; } - public string Name { get; } + public IConventionComplexTypeBuilder ComplexTypeBuilder { get; } = complexTypeBuilder; + public string Name { get; } = name; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnComplexTypeMemberIgnored(ComplexTypeBuilder, Name); } - private sealed class OnComplexTypeAnnotationChangedNode : ConventionNode + private sealed class OnComplexTypeAnnotationChangedNode( + IConventionComplexTypeBuilder propertyBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnComplexTypeAnnotationChangedNode( - IConventionComplexTypeBuilder propertyBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - ComplexTypeBuilder = propertyBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionComplexTypeBuilder ComplexTypeBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionComplexTypeBuilder ComplexTypeBuilder { get; } = propertyBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnComplexTypeAnnotationChanged( ComplexTypeBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnComplexPropertyAddedNode : ConventionNode + private sealed class OnComplexPropertyAddedNode(IConventionComplexPropertyBuilder propertyBuilder) : ConventionNode { - public OnComplexPropertyAddedNode(IConventionComplexPropertyBuilder propertyBuilder) - { - PropertyBuilder = propertyBuilder; - } - - public IConventionComplexPropertyBuilder PropertyBuilder { get; } + public IConventionComplexPropertyBuilder PropertyBuilder { get; } = propertyBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnComplexPropertyAdded(PropertyBuilder); } - private sealed class OnComplexPropertyRemovedNode : ConventionNode + private sealed class OnComplexPropertyRemovedNode(IConventionTypeBaseBuilder modelBuilder, IConventionComplexProperty entityType) + : ConventionNode { - public OnComplexPropertyRemovedNode(IConventionTypeBaseBuilder modelBuilder, IConventionComplexProperty entityType) - { - TypeBaseBuilder = modelBuilder; - ComplexProperty = entityType; - } - - public IConventionTypeBaseBuilder TypeBaseBuilder { get; } - public IConventionComplexProperty ComplexProperty { get; } + public IConventionTypeBaseBuilder TypeBaseBuilder { get; } = modelBuilder; + public IConventionComplexProperty ComplexProperty { get; } = entityType; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnComplexPropertyRemoved(TypeBaseBuilder, ComplexProperty); } - private sealed class OnComplexPropertyNullabilityChangedNode : ConventionNode + private sealed class OnComplexPropertyNullabilityChangedNode(IConventionComplexPropertyBuilder propertyBuilder) : ConventionNode { - public OnComplexPropertyNullabilityChangedNode(IConventionComplexPropertyBuilder propertyBuilder) - { - PropertyBuilder = propertyBuilder; - } - - public IConventionComplexPropertyBuilder PropertyBuilder { get; } + public IConventionComplexPropertyBuilder PropertyBuilder { get; } = propertyBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnComplexPropertyNullabilityChanged(PropertyBuilder); } - private sealed class OnComplexPropertyFieldChangedNode : ConventionNode + private sealed class OnComplexPropertyFieldChangedNode( + IConventionComplexPropertyBuilder propertyBuilder, + FieldInfo? newFieldInfo, + FieldInfo? oldFieldInfo) + : ConventionNode { - public OnComplexPropertyFieldChangedNode( - IConventionComplexPropertyBuilder propertyBuilder, - FieldInfo? newFieldInfo, - FieldInfo? oldFieldInfo) - { - PropertyBuilder = propertyBuilder; - NewFieldInfo = newFieldInfo; - OldFieldInfo = oldFieldInfo; - } - - public IConventionComplexPropertyBuilder PropertyBuilder { get; } - public FieldInfo? NewFieldInfo { get; } - public FieldInfo? OldFieldInfo { get; } + public IConventionComplexPropertyBuilder PropertyBuilder { get; } = propertyBuilder; + public FieldInfo? NewFieldInfo { get; } = newFieldInfo; + public FieldInfo? OldFieldInfo { get; } = oldFieldInfo; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnComplexPropertyFieldChanged(PropertyBuilder, NewFieldInfo, OldFieldInfo); } - private sealed class OnComplexPropertyAnnotationChangedNode : ConventionNode + private sealed class OnComplexPropertyAnnotationChangedNode( + IConventionComplexPropertyBuilder propertyBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnComplexPropertyAnnotationChangedNode( - IConventionComplexPropertyBuilder propertyBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - PropertyBuilder = propertyBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionComplexPropertyBuilder PropertyBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionComplexPropertyBuilder PropertyBuilder { get; } = propertyBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnComplexPropertyAnnotationChanged( PropertyBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnForeignKeyAddedNode : ConventionNode + private sealed class OnForeignKeyAddedNode(IConventionForeignKeyBuilder relationshipBuilder) : ConventionNode { - public OnForeignKeyAddedNode(IConventionForeignKeyBuilder relationshipBuilder) - { - RelationshipBuilder = relationshipBuilder; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyAdded(RelationshipBuilder); } - private sealed class OnForeignKeyRemovedNode : ConventionNode + private sealed class OnForeignKeyRemovedNode(IConventionEntityTypeBuilder entityTypeBuilder, IConventionForeignKey foreignKey) + : ConventionNode { - public OnForeignKeyRemovedNode(IConventionEntityTypeBuilder entityTypeBuilder, IConventionForeignKey foreignKey) - { - EntityTypeBuilder = entityTypeBuilder; - ForeignKey = foreignKey; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionForeignKey ForeignKey { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public IConventionForeignKey ForeignKey { get; } = foreignKey; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyRemoved(EntityTypeBuilder, ForeignKey); } - private sealed class OnForeignKeyAnnotationChangedNode : ConventionNode + private sealed class OnForeignKeyAnnotationChangedNode( + IConventionForeignKeyBuilder relationshipBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnForeignKeyAnnotationChangedNode( - IConventionForeignKeyBuilder relationshipBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - RelationshipBuilder = relationshipBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyAnnotationChanged( RelationshipBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnForeignKeyPropertiesChangedNode : ConventionNode + private sealed class OnForeignKeyPropertiesChangedNode( + IConventionForeignKeyBuilder relationshipBuilder, + IReadOnlyList oldDependentProperties, + IConventionKey oldPrincipalKey) + : ConventionNode { - public OnForeignKeyPropertiesChangedNode( - IConventionForeignKeyBuilder relationshipBuilder, - IReadOnlyList oldDependentProperties, - IConventionKey oldPrincipalKey) - { - RelationshipBuilder = relationshipBuilder; - OldDependentProperties = oldDependentProperties; - OldPrincipalKey = oldPrincipalKey; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } - public IReadOnlyList OldDependentProperties { get; } - public IConventionKey OldPrincipalKey { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; + public IReadOnlyList OldDependentProperties { get; } = oldDependentProperties; + public IConventionKey OldPrincipalKey { get; } = oldPrincipalKey; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyPropertiesChanged( RelationshipBuilder, OldDependentProperties, OldPrincipalKey); } - private sealed class OnForeignKeyUniquenessChangedNode : ConventionNode + private sealed class OnForeignKeyUniquenessChangedNode(IConventionForeignKeyBuilder relationshipBuilder) : ConventionNode { - public OnForeignKeyUniquenessChangedNode(IConventionForeignKeyBuilder relationshipBuilder) - { - RelationshipBuilder = relationshipBuilder; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyUniquenessChanged(RelationshipBuilder); } - private sealed class OnForeignKeyRequirednessChangedNode : ConventionNode + private sealed class OnForeignKeyRequirednessChangedNode(IConventionForeignKeyBuilder relationshipBuilder) : ConventionNode { - public OnForeignKeyRequirednessChangedNode(IConventionForeignKeyBuilder relationshipBuilder) - { - RelationshipBuilder = relationshipBuilder; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyRequirednessChanged(RelationshipBuilder); } - private sealed class OnForeignKeyDependentRequirednessChangedNode : ConventionNode + private sealed class OnForeignKeyDependentRequirednessChangedNode(IConventionForeignKeyBuilder relationshipBuilder) : ConventionNode { - public OnForeignKeyDependentRequirednessChangedNode(IConventionForeignKeyBuilder relationshipBuilder) - { - RelationshipBuilder = relationshipBuilder; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyDependentRequirednessChanged(RelationshipBuilder); } - private sealed class OnForeignKeyOwnershipChangedNode : ConventionNode + private sealed class OnForeignKeyOwnershipChangedNode(IConventionForeignKeyBuilder relationshipBuilder) : ConventionNode { - public OnForeignKeyOwnershipChangedNode(IConventionForeignKeyBuilder relationshipBuilder) - { - RelationshipBuilder = relationshipBuilder; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyOwnershipChanged(RelationshipBuilder); } - private sealed class OnForeignKeyNullNavigationSetNode : ConventionNode + private sealed class OnForeignKeyNullNavigationSetNode(IConventionForeignKeyBuilder relationshipBuilder, bool pointsToPrincipal) + : ConventionNode { - public OnForeignKeyNullNavigationSetNode(IConventionForeignKeyBuilder relationshipBuilder, bool pointsToPrincipal) - { - RelationshipBuilder = relationshipBuilder; - PointsToPrincipal = pointsToPrincipal; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } - public bool PointsToPrincipal { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; + public bool PointsToPrincipal { get; } = pointsToPrincipal; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyNullNavigationSet(RelationshipBuilder, PointsToPrincipal); } - private sealed class OnForeignKeyPrincipalEndChangedNode : ConventionNode + private sealed class OnForeignKeyPrincipalEndChangedNode(IConventionForeignKeyBuilder relationshipBuilder) : ConventionNode { - public OnForeignKeyPrincipalEndChangedNode(IConventionForeignKeyBuilder relationshipBuilder) - { - RelationshipBuilder = relationshipBuilder; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyPrincipalEndChanged(RelationshipBuilder); } - private sealed class OnNavigationAddedNode : ConventionNode + private sealed class OnNavigationAddedNode(IConventionNavigationBuilder navigationBuilder) : ConventionNode { - public OnNavigationAddedNode(IConventionNavigationBuilder navigationBuilder) - { - NavigationBuilder = navigationBuilder; - } - - public IConventionNavigationBuilder NavigationBuilder { get; } + public IConventionNavigationBuilder NavigationBuilder { get; } = navigationBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnNavigationAdded(NavigationBuilder); } - private sealed class OnNavigationAnnotationChangedNode : ConventionNode + private sealed class OnNavigationAnnotationChangedNode( + IConventionForeignKeyBuilder relationshipBuilder, + IConventionNavigation navigation, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnNavigationAnnotationChangedNode( - IConventionForeignKeyBuilder relationshipBuilder, - IConventionNavigation navigation, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - RelationshipBuilder = relationshipBuilder; - Navigation = navigation; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionForeignKeyBuilder RelationshipBuilder { get; } - public IConventionNavigation Navigation { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionForeignKeyBuilder RelationshipBuilder { get; } = relationshipBuilder; + public IConventionNavigation Navigation { get; } = navigation; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnNavigationAnnotationChanged( RelationshipBuilder, Navigation, Name, Annotation, OldAnnotation); } - private sealed class OnNavigationRemovedNode : ConventionNode + private sealed class OnNavigationRemovedNode( + IConventionEntityTypeBuilder sourceEntityTypeBuilder, + IConventionEntityTypeBuilder targetEntityTypeBuilder, + string navigationName, + MemberInfo? memberInfo) + : ConventionNode { - public OnNavigationRemovedNode( - IConventionEntityTypeBuilder sourceEntityTypeBuilder, - IConventionEntityTypeBuilder targetEntityTypeBuilder, - string navigationName, - MemberInfo? memberInfo) - { - SourceEntityTypeBuilder = sourceEntityTypeBuilder; - TargetEntityTypeBuilder = targetEntityTypeBuilder; - NavigationName = navigationName; - MemberInfo = memberInfo; - } - - public IConventionEntityTypeBuilder SourceEntityTypeBuilder { get; } - public IConventionEntityTypeBuilder TargetEntityTypeBuilder { get; } - public string NavigationName { get; } - public MemberInfo? MemberInfo { get; } + public IConventionEntityTypeBuilder SourceEntityTypeBuilder { get; } = sourceEntityTypeBuilder; + public IConventionEntityTypeBuilder TargetEntityTypeBuilder { get; } = targetEntityTypeBuilder; + public string NavigationName { get; } = navigationName; + public MemberInfo? MemberInfo { get; } = memberInfo; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnNavigationRemoved( SourceEntityTypeBuilder, TargetEntityTypeBuilder, NavigationName, MemberInfo); } - private sealed class OnSkipNavigationAddedNode : ConventionNode + private sealed class OnSkipNavigationAddedNode(IConventionSkipNavigationBuilder navigationBuilder) : ConventionNode { - public OnSkipNavigationAddedNode(IConventionSkipNavigationBuilder navigationBuilder) - { - NavigationBuilder = navigationBuilder; - } - - public IConventionSkipNavigationBuilder NavigationBuilder { get; } + public IConventionSkipNavigationBuilder NavigationBuilder { get; } = navigationBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnSkipNavigationAdded(NavigationBuilder); } - private sealed class OnSkipNavigationAnnotationChangedNode : ConventionNode + private sealed class OnSkipNavigationAnnotationChangedNode( + IConventionSkipNavigationBuilder navigationBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnSkipNavigationAnnotationChangedNode( - IConventionSkipNavigationBuilder navigationBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - NavigationBuilder = navigationBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionSkipNavigationBuilder NavigationBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionSkipNavigationBuilder NavigationBuilder { get; } = navigationBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnSkipNavigationAnnotationChanged( NavigationBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnSkipNavigationForeignKeyChangedNode : ConventionNode + private sealed class OnSkipNavigationForeignKeyChangedNode( + IConventionSkipNavigationBuilder navigationBuilder, + IConventionForeignKey? foreignKey, + IConventionForeignKey? oldForeignKey) + : ConventionNode { - public OnSkipNavigationForeignKeyChangedNode( - IConventionSkipNavigationBuilder navigationBuilder, - IConventionForeignKey? foreignKey, - IConventionForeignKey? oldForeignKey) - { - NavigationBuilder = navigationBuilder; - ForeignKey = foreignKey; - OldForeignKey = oldForeignKey; - } - - public IConventionSkipNavigationBuilder NavigationBuilder { get; } - public IConventionForeignKey? ForeignKey { get; } - public IConventionForeignKey? OldForeignKey { get; } + public IConventionSkipNavigationBuilder NavigationBuilder { get; } = navigationBuilder; + public IConventionForeignKey? ForeignKey { get; } = foreignKey; + public IConventionForeignKey? OldForeignKey { get; } = oldForeignKey; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnSkipNavigationForeignKeyChanged(NavigationBuilder, ForeignKey, OldForeignKey); } - private sealed class OnSkipNavigationInverseChangedNode : ConventionNode + private sealed class OnSkipNavigationInverseChangedNode( + IConventionSkipNavigationBuilder navigationBuilder, + IConventionSkipNavigation? inverse, + IConventionSkipNavigation? oldInverse) + : ConventionNode { - public OnSkipNavigationInverseChangedNode( - IConventionSkipNavigationBuilder navigationBuilder, - IConventionSkipNavigation? inverse, - IConventionSkipNavigation? oldInverse) - { - NavigationBuilder = navigationBuilder; - Inverse = inverse; - OldInverse = oldInverse; - } - - public IConventionSkipNavigationBuilder NavigationBuilder { get; } - public IConventionSkipNavigation? Inverse { get; } - public IConventionSkipNavigation? OldInverse { get; } + public IConventionSkipNavigationBuilder NavigationBuilder { get; } = navigationBuilder; + public IConventionSkipNavigation? Inverse { get; } = inverse; + public IConventionSkipNavigation? OldInverse { get; } = oldInverse; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnSkipNavigationInverseChanged(NavigationBuilder, Inverse, OldInverse); } - private sealed class OnSkipNavigationRemovedNode : ConventionNode + private sealed class OnSkipNavigationRemovedNode( + IConventionEntityTypeBuilder entityTypeBuilder, + IConventionSkipNavigation navigation) + : ConventionNode { - public OnSkipNavigationRemovedNode( - IConventionEntityTypeBuilder entityTypeBuilder, - IConventionSkipNavigation navigation) - { - EntityTypeBuilder = entityTypeBuilder; - Navigation = navigation; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionSkipNavigation Navigation { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public IConventionSkipNavigation Navigation { get; } = navigation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnSkipNavigationRemoved(EntityTypeBuilder, Navigation); } - private sealed class OnTriggerAddedNode : ConventionNode + private sealed class OnTriggerAddedNode(IConventionTriggerBuilder triggerBuilder) : ConventionNode { - public OnTriggerAddedNode(IConventionTriggerBuilder triggerBuilder) - { - TriggerBuilder = triggerBuilder; - } - - public IConventionTriggerBuilder TriggerBuilder { get; } + public IConventionTriggerBuilder TriggerBuilder { get; } = triggerBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnTriggerAdded(TriggerBuilder); } - private sealed class OnTriggerRemovedNode : ConventionNode + private sealed class OnTriggerRemovedNode( + IConventionEntityTypeBuilder entityTypeBuilder, + IConventionTrigger trigger) + : ConventionNode { - public OnTriggerRemovedNode( - IConventionEntityTypeBuilder entityTypeBuilder, - IConventionTrigger trigger) - { - EntityTypeBuilder = entityTypeBuilder; - Trigger = trigger; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionTrigger Trigger { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public IConventionTrigger Trigger { get; } = trigger; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnTriggerRemoved(EntityTypeBuilder, Trigger); } - private sealed class OnKeyAddedNode : ConventionNode + private sealed class OnKeyAddedNode(IConventionKeyBuilder keyBuilder) : ConventionNode { - public OnKeyAddedNode(IConventionKeyBuilder keyBuilder) - { - KeyBuilder = keyBuilder; - } - - public IConventionKeyBuilder KeyBuilder { get; } + public IConventionKeyBuilder KeyBuilder { get; } = keyBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnKeyAdded(KeyBuilder); } - private sealed class OnKeyRemovedNode : ConventionNode + private sealed class OnKeyRemovedNode(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key) : ConventionNode { - public OnKeyRemovedNode(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key) - { - EntityTypeBuilder = entityTypeBuilder; - Key = key; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionKey Key { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public IConventionKey Key { get; } = key; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnKeyRemoved(EntityTypeBuilder, Key); } - private sealed class OnKeyAnnotationChangedNode : ConventionNode + private sealed class OnKeyAnnotationChangedNode( + IConventionKeyBuilder keyBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnKeyAnnotationChangedNode( - IConventionKeyBuilder keyBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - KeyBuilder = keyBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionKeyBuilder KeyBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionKeyBuilder KeyBuilder { get; } = keyBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnKeyAnnotationChanged( KeyBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnEntityTypePrimaryKeyChangedNode : ConventionNode + private sealed class OnEntityTypePrimaryKeyChangedNode( + IConventionEntityTypeBuilder entityTypeBuilder, + IConventionKey? newPrimaryKey, + IConventionKey? previousPrimaryKey) + : ConventionNode { - public OnEntityTypePrimaryKeyChangedNode( - IConventionEntityTypeBuilder entityTypeBuilder, - IConventionKey? newPrimaryKey, - IConventionKey? previousPrimaryKey) - { - EntityTypeBuilder = entityTypeBuilder; - NewPrimaryKey = newPrimaryKey; - PreviousPrimaryKey = previousPrimaryKey; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionKey? NewPrimaryKey { get; } - public IConventionKey? PreviousPrimaryKey { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public IConventionKey? NewPrimaryKey { get; } = newPrimaryKey; + public IConventionKey? PreviousPrimaryKey { get; } = previousPrimaryKey; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypePrimaryKeyChanged( EntityTypeBuilder, NewPrimaryKey, PreviousPrimaryKey); } - private sealed class OnIndexAddedNode : ConventionNode + private sealed class OnIndexAddedNode(IConventionIndexBuilder indexBuilder) : ConventionNode { - public OnIndexAddedNode(IConventionIndexBuilder indexBuilder) - { - IndexBuilder = indexBuilder; - } - - public IConventionIndexBuilder IndexBuilder { get; } + public IConventionIndexBuilder IndexBuilder { get; } = indexBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnIndexAdded(IndexBuilder); } - private sealed class OnIndexRemovedNode : ConventionNode + private sealed class OnIndexRemovedNode(IConventionEntityTypeBuilder entityTypeBuilder, IConventionIndex index) + : ConventionNode { - public OnIndexRemovedNode(IConventionEntityTypeBuilder entityTypeBuilder, IConventionIndex index) - { - EntityTypeBuilder = entityTypeBuilder; - Index = index; - } - - public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionIndex Index { get; } + public IConventionEntityTypeBuilder EntityTypeBuilder { get; } = entityTypeBuilder; + public IConventionIndex Index { get; } = index; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnIndexRemoved(EntityTypeBuilder, Index); } - private sealed class OnIndexUniquenessChangedNode : ConventionNode + private sealed class OnIndexUniquenessChangedNode(IConventionIndexBuilder indexBuilder) : ConventionNode { - public OnIndexUniquenessChangedNode(IConventionIndexBuilder indexBuilder) - { - IndexBuilder = indexBuilder; - } - - public IConventionIndexBuilder IndexBuilder { get; } + public IConventionIndexBuilder IndexBuilder { get; } = indexBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnIndexUniquenessChanged(IndexBuilder); } - private sealed class OnIndexSortOrderChangedNode : ConventionNode + private sealed class OnIndexSortOrderChangedNode(IConventionIndexBuilder indexBuilder) : ConventionNode { - public OnIndexSortOrderChangedNode(IConventionIndexBuilder indexBuilder) - { - IndexBuilder = indexBuilder; - } - - public IConventionIndexBuilder IndexBuilder { get; } + public IConventionIndexBuilder IndexBuilder { get; } = indexBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnIndexSortOrderChanged(IndexBuilder); } - private sealed class OnIndexAnnotationChangedNode : ConventionNode + private sealed class OnIndexAnnotationChangedNode( + IConventionIndexBuilder indexBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnIndexAnnotationChangedNode( - IConventionIndexBuilder indexBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - IndexBuilder = indexBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionIndexBuilder IndexBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionIndexBuilder IndexBuilder { get; } = indexBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnIndexAnnotationChanged( IndexBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnPropertyAddedNode : ConventionNode + private sealed class OnPropertyAddedNode(IConventionPropertyBuilder propertyBuilder) : ConventionNode { - public OnPropertyAddedNode(IConventionPropertyBuilder propertyBuilder) - { - PropertyBuilder = propertyBuilder; - } - - public IConventionPropertyBuilder PropertyBuilder { get; } + public IConventionPropertyBuilder PropertyBuilder { get; } = propertyBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnPropertyAdded(PropertyBuilder); } - private sealed class OnPropertyNullabilityChangedNode : ConventionNode + private sealed class OnPropertyNullabilityChangedNode(IConventionPropertyBuilder propertyBuilder) : ConventionNode { - public OnPropertyNullabilityChangedNode(IConventionPropertyBuilder propertyBuilder) - { - PropertyBuilder = propertyBuilder; - } - - public IConventionPropertyBuilder PropertyBuilder { get; } + public IConventionPropertyBuilder PropertyBuilder { get; } = propertyBuilder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnPropertyNullabilityChanged(PropertyBuilder); } - private sealed class OnElementTypeNullabilityChangedNode : ConventionNode + private sealed class OnElementTypeNullabilityChangedNode(IConventionElementTypeBuilder builder) : ConventionNode { - public OnElementTypeNullabilityChangedNode(IConventionElementTypeBuilder builder) - { - ElementTypeBuilder = builder; - } - - public IConventionElementTypeBuilder ElementTypeBuilder { get; } + public IConventionElementTypeBuilder ElementTypeBuilder { get; } = builder; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnElementTypeNullabilityChanged(ElementTypeBuilder); } - private sealed class OnPropertyFieldChangedNode : ConventionNode + private sealed class OnPropertyFieldChangedNode( + IConventionPropertyBuilder propertyBuilder, + FieldInfo? newFieldInfo, + FieldInfo? oldFieldInfo) + : ConventionNode { - public OnPropertyFieldChangedNode(IConventionPropertyBuilder propertyBuilder, FieldInfo? newFieldInfo, FieldInfo? oldFieldInfo) - { - PropertyBuilder = propertyBuilder; - NewFieldInfo = newFieldInfo; - OldFieldInfo = oldFieldInfo; - } - - public IConventionPropertyBuilder PropertyBuilder { get; } - public FieldInfo? NewFieldInfo { get; } - public FieldInfo? OldFieldInfo { get; } + public IConventionPropertyBuilder PropertyBuilder { get; } = propertyBuilder; + public FieldInfo? NewFieldInfo { get; } = newFieldInfo; + public FieldInfo? OldFieldInfo { get; } = oldFieldInfo; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnPropertyFieldChanged(PropertyBuilder, NewFieldInfo, OldFieldInfo); } - private sealed class OnPropertyElementTypeChangedNode : ConventionNode + private sealed class OnPropertyElementTypeChangedNode( + IConventionPropertyBuilder propertyBuilder, + IElementType? newElementType, + IElementType? oldElementType) + : ConventionNode { - public OnPropertyElementTypeChangedNode( - IConventionPropertyBuilder propertyBuilder, - IElementType? newElementType, - IElementType? oldElementType) - { - PropertyBuilder = propertyBuilder; - NewElementType = newElementType; - OldElementType = oldElementType; - } - - public IConventionPropertyBuilder PropertyBuilder { get; } - public IElementType? NewElementType { get; } - public IElementType? OldElementType { get; } + public IConventionPropertyBuilder PropertyBuilder { get; } = propertyBuilder; + public IElementType? NewElementType { get; } = newElementType; + public IElementType? OldElementType { get; } = oldElementType; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnPropertyElementTypeChanged(PropertyBuilder, NewElementType, OldElementType); } - private sealed class OnPropertyAnnotationChangedNode : ConventionNode + private sealed class OnPropertyAnnotationChangedNode( + IConventionPropertyBuilder propertyBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnPropertyAnnotationChangedNode( - IConventionPropertyBuilder propertyBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - PropertyBuilder = propertyBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionPropertyBuilder PropertyBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionPropertyBuilder PropertyBuilder { get; } = propertyBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnPropertyAnnotationChanged( PropertyBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnElementTypeAnnotationChangedNode : ConventionNode + private sealed class OnElementTypeAnnotationChangedNode( + IConventionElementTypeBuilder elementTypeBuilder, + string name, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) + : ConventionNode { - public OnElementTypeAnnotationChangedNode( - IConventionElementTypeBuilder elementTypeBuilder, - string name, - IConventionAnnotation? annotation, - IConventionAnnotation? oldAnnotation) - { - ElementTypeBuilder = elementTypeBuilder; - Name = name; - Annotation = annotation; - OldAnnotation = oldAnnotation; - } - - public IConventionElementTypeBuilder ElementTypeBuilder { get; } - public string Name { get; } - public IConventionAnnotation? Annotation { get; } - public IConventionAnnotation? OldAnnotation { get; } + public IConventionElementTypeBuilder ElementTypeBuilder { get; } = elementTypeBuilder; + public string Name { get; } = name; + public IConventionAnnotation? Annotation { get; } = annotation; + public IConventionAnnotation? OldAnnotation { get; } = oldAnnotation; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnElementTypeAnnotationChanged( ElementTypeBuilder, Name, Annotation, OldAnnotation); } - private sealed class OnPropertyRemovedNode : ConventionNode + private sealed class OnPropertyRemovedNode( + IConventionTypeBaseBuilder typeBaseBuilder, + IConventionProperty property) + : ConventionNode { - public OnPropertyRemovedNode( - IConventionTypeBaseBuilder typeBaseBuilder, - IConventionProperty property) - { - TypeBaseBuilder = typeBaseBuilder; - Property = property; - } - - public IConventionTypeBaseBuilder TypeBaseBuilder { get; } - public IConventionProperty Property { get; } + public IConventionTypeBaseBuilder TypeBaseBuilder { get; } = typeBaseBuilder; + public IConventionProperty Property { get; } = property; public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnPropertyRemoved(TypeBaseBuilder, Property); diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs index 6c2770f6bd2..45e87dc3890 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs @@ -145,6 +145,35 @@ public IConventionModelBuilder OnModelInitialized(IConventionModelBuilder modelB return annotation; } + public override string? OnModelEmbeddedDiscriminatorNameChanged( + IConventionModelBuilder modelBuilder, string? oldName, string? newName) + { + using (_dispatcher.DelayConventions()) + { + _stringConventionContext.ResetState(oldName); +#if DEBUG + var initialValue = modelBuilder.Metadata.GetEmbeddedDiscriminatorName(); +#endif + foreach (var modelConvention in _conventionSet.ModelEmbeddedDiscriminatorNameConventions) + { + modelConvention.ProcessEmbeddedDiscriminatorName(modelBuilder, oldName, newName, _stringConventionContext); + + if (_stringConventionContext.ShouldStopProcessing()) + { + return _stringConventionContext.Result; + } + +#if DEBUG + Check.DebugAssert( + initialValue == (string?)modelBuilder.Metadata.GetEmbeddedDiscriminatorName(), + $"Convention {modelConvention.GetType().Name} changed value without terminating"); +#endif + } + } + + return newName; + } + public override string? OnTypeIgnored(IConventionModelBuilder modelBuilder, string name, Type? type) { using (_dispatcher.DelayConventions()) diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs index 8120df591d6..e8881bc3def 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs @@ -68,6 +68,12 @@ public virtual IConventionModelBuilder OnModelFinalizing(IConventionModelBuilder IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation) { + if (name == CoreAnnotationNames.EmbeddedDiscriminatorName) + { + _scope.OnModelEmbeddedDiscriminatorNameChanged(modelBuilder, oldAnnotation?.Name, annotation?.Name); + return annotation; + } + if (CoreAnnotationNames.AllNames.Contains(name)) { return annotation; diff --git a/src/EFCore/Metadata/IConventionModel.cs b/src/EFCore/Metadata/IConventionModel.cs index f30bdd8510f..c31023226d8 100644 --- a/src/EFCore/Metadata/IConventionModel.cs +++ b/src/EFCore/Metadata/IConventionModel.cs @@ -58,6 +58,20 @@ public interface IConventionModel : IReadOnlyModel, IConventionAnnotatable /// The configuration source for . ConfigurationSource? GetPropertyAccessModeConfigurationSource(); + /// + /// Sets the name to use for discriminator properties embedded in JSON documents. The default is "$type". + /// + /// The property name, or to clear the name set. + /// Indicates whether the configuration was specified using a data annotation. + /// The configured value. + string? SetEmbeddedDiscriminatorName(string? name, bool fromDataAnnotation = false); + + /// + /// Returns the configuration source for . + /// + /// The configuration source for . + ConfigurationSource? GetEmbeddedDiscriminatorNameConfigurationSource(); + /// /// Sets the default change tracking strategy to use for entities in the model. This strategy indicates how the /// context detects changes to properties for an instance of an entity type. diff --git a/src/EFCore/Metadata/IMutableModel.cs b/src/EFCore/Metadata/IMutableModel.cs index 6ef2ee0fd02..350013f8eaf 100644 --- a/src/EFCore/Metadata/IMutableModel.cs +++ b/src/EFCore/Metadata/IMutableModel.cs @@ -45,6 +45,12 @@ public interface IMutableModel : IReadOnlyModel, IMutableAnnotatable /// The , or to clear the mode set. void SetPropertyAccessMode(PropertyAccessMode? propertyAccessMode); + /// + /// Sets the name to use for discriminator properties embedded in JSON documents. The default is "$type". + /// + /// The property name, or to clear the name set. + void SetEmbeddedDiscriminatorName(string? name); + /// /// Sets the default change tracking strategy to use for entities in the model. This strategy indicates how the /// context detects changes to properties for an instance of an entity type. diff --git a/src/EFCore/Metadata/IReadOnlyModel.cs b/src/EFCore/Metadata/IReadOnlyModel.cs index b115bf6c5e3..055f04aed15 100644 --- a/src/EFCore/Metadata/IReadOnlyModel.cs +++ b/src/EFCore/Metadata/IReadOnlyModel.cs @@ -45,6 +45,13 @@ public interface IReadOnlyModel : IReadOnlyAnnotatable [DebuggerStepThrough] PropertyAccessMode GetPropertyAccessMode(); + /// + /// Gets the name to use for discriminator properties embedded in JSON documents. The default is "$type". + /// + /// The name. + [DebuggerStepThrough] + string GetEmbeddedDiscriminatorName(); + /// /// Gets the EF Core assembly version used to build this model. /// diff --git a/src/EFCore/Metadata/Internal/CoreAnnotationNames.cs b/src/EFCore/Metadata/Internal/CoreAnnotationNames.cs index c35924b8633..3db5be6b3f8 100644 --- a/src/EFCore/Metadata/Internal/CoreAnnotationNames.cs +++ b/src/EFCore/Metadata/Internal/CoreAnnotationNames.cs @@ -115,6 +115,14 @@ public static class CoreAnnotationNames /// public const string DiscriminatorValue = "DiscriminatorValue"; + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public const string EmbeddedDiscriminatorName = "EmbeddedDiscriminatorName"; + /// /// 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 @@ -385,6 +393,7 @@ public static class CoreAnnotationNames DiscriminatorProperty, DiscriminatorMappingComplete, DiscriminatorValue, + EmbeddedDiscriminatorName, ValueConverter, ValueConverterType, ValueComparer, diff --git a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs index 845e65ec0d2..4358cfffdf3 100644 --- a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs @@ -797,6 +797,34 @@ public virtual bool CanSetPropertyAccessMode( => configurationSource.Overrides(Metadata.GetPropertyAccessModeConfigurationSource()) || Metadata.GetPropertyAccessMode() == propertyAccessMode; + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual InternalModelBuilder? HasEmbeddedDiscriminatorName(string? name, ConfigurationSource configurationSource) + { + if (CanSetEmbeddedDiscriminatorName(name, configurationSource)) + { + Metadata.SetEmbeddedDiscriminatorName(name, configurationSource); + + return this; + } + + return null; + } + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual bool CanSetEmbeddedDiscriminatorName(string? name, ConfigurationSource configurationSource) + => configurationSource.Overrides(Metadata.GetEmbeddedDiscriminatorNameConfigurationSource()) + || Metadata.GetEmbeddedDiscriminatorName() == name; + /// /// 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 @@ -1113,4 +1141,26 @@ bool IConventionModelBuilder.CanSetChangeTrackingStrategy(ChangeTrackingStrategy bool IConventionModelBuilder.CanSetPropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => CanSetPropertyAccessMode( propertyAccessMode, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + [DebuggerStepThrough] + IConventionModelBuilder? IConventionModelBuilder.HasEmbeddedDiscriminatorName(string? name, bool fromDataAnnotation) + => HasEmbeddedDiscriminatorName( + name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + [DebuggerStepThrough] + bool IConventionModelBuilder.CanSetEmbeddedDiscriminatorName(string? name, bool fromDataAnnotation) + => CanSetEmbeddedDiscriminatorName( + name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); } diff --git a/src/EFCore/Metadata/Internal/Model.cs b/src/EFCore/Metadata/Internal/Model.cs index 5c3a7b7ead6..7bf8d3eae99 100644 --- a/src/EFCore/Metadata/Internal/Model.cs +++ b/src/EFCore/Metadata/Internal/Model.cs @@ -1007,6 +1007,45 @@ public virtual PropertyAccessMode GetPropertyAccessMode() public virtual ConfigurationSource? GetPropertyAccessModeConfigurationSource() => FindAnnotation(CoreAnnotationNames.PropertyAccessMode)?.GetConfigurationSource(); + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual string GetEmbeddedDiscriminatorName() + => (string?)this[CoreAnnotationNames.EmbeddedDiscriminatorName] + ?? DefaultEmbeddedDiscriminatorName; + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public const string DefaultEmbeddedDiscriminatorName = "$type"; + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual string? SetEmbeddedDiscriminatorName( + string? name, + ConfigurationSource configurationSource) + => (string?)SetOrRemoveAnnotation( + CoreAnnotationNames.EmbeddedDiscriminatorName, name, configurationSource)?.Value; + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + public virtual ConfigurationSource? GetEmbeddedDiscriminatorNameConfigurationSource() + => FindAnnotation(CoreAnnotationNames.EmbeddedDiscriminatorName)?.GetConfigurationSource(); + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in @@ -1254,6 +1293,30 @@ void IMutableModel.SetPropertyAccessMode(PropertyAccessMode? propertyAccessMode) propertyAccessMode, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + [DebuggerStepThrough] + void IMutableModel.SetEmbeddedDiscriminatorName(string? name) + => SetEmbeddedDiscriminatorName(name, ConfigurationSource.Explicit); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + [DebuggerStepThrough] + string? IConventionModel.SetEmbeddedDiscriminatorName( + string? name, + bool fromDataAnnotation) + => SetEmbeddedDiscriminatorName( + name, + fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore/Metadata/RuntimeModel.cs b/src/EFCore/Metadata/RuntimeModel.cs index 19051377762..f4271a0ed1a 100644 --- a/src/EFCore/Metadata/RuntimeModel.cs +++ b/src/EFCore/Metadata/RuntimeModel.cs @@ -343,6 +343,11 @@ bool IRuntimeModel.SkipDetectChanges PropertyAccessMode IReadOnlyModel.GetPropertyAccessMode() => throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData); + /// + [DebuggerStepThrough] + string IReadOnlyModel.GetEmbeddedDiscriminatorName() + => throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData); + /// [DebuggerStepThrough] ChangeTrackingStrategy IReadOnlyModel.GetChangeTrackingStrategy() diff --git a/src/EFCore/ModelBuilder.cs b/src/EFCore/ModelBuilder.cs index 2946849ba9d..594632ed51a 100644 --- a/src/EFCore/ModelBuilder.cs +++ b/src/EFCore/ModelBuilder.cs @@ -638,8 +638,20 @@ public virtual ModelBuilder UsePropertyAccessMode(PropertyAccessMode propertyAcc } /// - /// Forces post-processing on the model such that it is ready for use by the runtime. This post - /// processing happens automatically when using ; this method allows it to be run + /// Sets the name to use for discriminator properties embedded in JSON documents. The default is "$type". + /// + /// The property name, or to clear the name set. + /// The same instance so that additional configuration calls can be chained. + public virtual ModelBuilder HasEmbeddedDiscriminatorName(string name) + { + Builder.HasEmbeddedDiscriminatorName(name, ConfigurationSource.Explicit); + + return this; + } + + /// + /// Forces post-processing on the model such that it is ready for use by the runtime. This post-processing + /// happens automatically when using ; this method allows it to be run /// explicitly in cases where the automatic execution is not possible. /// /// The finalized model. diff --git a/src/EFCore/Query/StructuralTypeShaperExpression.cs b/src/EFCore/Query/StructuralTypeShaperExpression.cs index 07c634650eb..03d9ebde198 100644 --- a/src/EFCore/Query/StructuralTypeShaperExpression.cs +++ b/src/EFCore/Query/StructuralTypeShaperExpression.cs @@ -34,8 +34,8 @@ private static readonly MethodInfo GetDiscriminatorValueMethod /// [UsedImplicitly] [EntityFrameworkInternal] - public static Exception CreateUnableToDiscriminateException(ITypeBase type, object discriminator) - => new InvalidOperationException(CoreStrings.UnableToDiscriminate(type.DisplayName(), discriminator.ToString())); + public static Exception CreateUnableToDiscriminateException(ITypeBase type, object? discriminator) + => new InvalidOperationException(CoreStrings.UnableToDiscriminate(type.DisplayName(), discriminator?.ToString())); /// /// Creates a new instance of the class. diff --git a/test/EFCore.Cosmos.FunctionalTests/BuiltInDataTypesCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/BuiltInDataTypesCosmosTest.cs index d749aabc5f0..344b0578db9 100644 --- a/test/EFCore.Cosmos.FunctionalTests/BuiltInDataTypesCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/BuiltInDataTypesCosmosTest.cs @@ -50,7 +50,7 @@ public override async Task Object_to_string_conversion() """ SELECT c["TestSignedByte"], c["TestByte"], c["TestInt16"], c["TestUnsignedInt16"], c["TestInt32"], c["TestUnsignedInt32"], c["TestInt64"], c["TestUnsignedInt64"], c["TestSingle"], c["TestDouble"], c["TestDecimal"], c["TestCharacter"], c["TestDateTime"], c["TestDateTimeOffset"], c["TestTimeSpan"], c["TestDateOnly"], c["TestTimeOnly"] FROM root c -WHERE ((c["Discriminator"] = "BuiltInDataTypes") AND (c["Id"] = 13)) +WHERE ((c["$type"] = "BuiltInDataTypes") AND (c["Id"] = 13)) """); } diff --git a/test/EFCore.Cosmos.FunctionalTests/CustomConvertersCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/CustomConvertersCosmosTest.cs index 91749bb09f7..0d40169a4cf 100644 --- a/test/EFCore.Cosmos.FunctionalTests/CustomConvertersCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/CustomConvertersCosmosTest.cs @@ -76,7 +76,7 @@ public override async Task Where_bool_gets_converted_to_equality_when_value_conv """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("Blog", "RssBlog") AND (c["IsVisible"] = "Y")) +WHERE (c["$type"] IN ("Blog", "RssBlog") AND (c["IsVisible"] = "Y")) """); } @@ -89,7 +89,7 @@ public override async Task Where_negated_bool_gets_converted_to_equality_when_va """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("Blog", "RssBlog") AND NOT((c["IsVisible"] = "Y"))) +WHERE (c["$type"] IN ("Blog", "RssBlog") AND NOT((c["IsVisible"] = "Y"))) """); } @@ -102,7 +102,7 @@ public override async Task Where_bool_gets_converted_to_equality_when_value_conv """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("Blog", "RssBlog") AND (c["IsVisible"] = "Y")) +WHERE (c["$type"] IN ("Blog", "RssBlog") AND (c["IsVisible"] = "Y")) """); } @@ -115,7 +115,7 @@ public override async Task Where_bool_gets_converted_to_equality_when_value_conv """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("Blog", "RssBlog") AND NOT((c["IndexerVisible"] = "Aye"))) +WHERE (c["$type"] IN ("Blog", "RssBlog") AND NOT((c["IndexerVisible"] = "Aye"))) """); } diff --git a/test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs b/test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs index 1ac57f03370..80b40a6e007 100644 --- a/test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs @@ -535,7 +535,7 @@ public virtual async Task Can_query_and_modify_nested_embedded_types() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("Vehicle", "PoweredVehicle") AND (c["Name"] = "AIM-9M Sidewinder")) +WHERE (c["$type"] IN ("Vehicle", "PoweredVehicle") AND (c["Name"] = "AIM-9M Sidewinder")) OFFSET 0 LIMIT 1 """); Assert.Equal("Heat-seeking", missile.Operator.Details.Type); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/FromSqlQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/FromSqlQueryCosmosTest.cs index 6c90934c2ba..dc052ecc5a2 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/FromSqlQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/FromSqlQueryCosmosTest.cs @@ -29,7 +29,7 @@ public Task FromSqlRaw_queryable_simple(bool async) { using var context = CreateContext(); var query = context.Set().FromSqlRaw( - """SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["ContactName"] LIKE '%z%'"""); + """SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["ContactName"] LIKE '%z%'"""); var actual = a ? await query.ToArrayAsync() @@ -42,7 +42,7 @@ public Task FromSqlRaw_queryable_simple(bool async) """ SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["ContactName"] LIKE '%z%' + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["ContactName"] LIKE '%z%' ) s """); }); @@ -52,7 +52,7 @@ public async Task FromSqlRaw_queryable_incorrect_discriminator_throws() { using var context = CreateContext(); var query = context.Set().FromSqlRaw(""" -SELECT * FROM root c WHERE c["Discriminator"] = "OrderDetail" +SELECT * FROM root c WHERE c["$type"] = "OrderDetail" """); var exception = await Assert.ThrowsAsync(() => query.ToArrayAsync()); @@ -71,7 +71,7 @@ public Task FromSqlRaw_queryable_simple_columns_out_of_order(bool async) using var context = CreateContext(); var query = context.Set().FromSqlRaw( """ -SELECT c["id"], c["Discriminator"], c["Region"], c["PostalCode"], c["Phone"], c["Fax"], c["Country"], c["ContactTitle"], c["ContactName"], c["CompanyName"], c["City"], c["Address"] FROM root c WHERE c["Discriminator"] = "Customer" +SELECT c["id"], c["$type"], c["Region"], c["PostalCode"], c["Phone"], c["Fax"], c["Country"], c["ContactTitle"], c["ContactName"], c["CompanyName"], c["City"], c["Address"] FROM root c WHERE c["$type"] = "Customer" """); var actual = a @@ -85,7 +85,7 @@ public Task FromSqlRaw_queryable_simple_columns_out_of_order(bool async) """ SELECT VALUE s FROM ( - SELECT c["id"], c["Discriminator"], c["Region"], c["PostalCode"], c["Phone"], c["Fax"], c["Country"], c["ContactTitle"], c["ContactName"], c["CompanyName"], c["City"], c["Address"] FROM root c WHERE c["Discriminator"] = "Customer" + SELECT c["id"], c["$type"], c["Region"], c["PostalCode"], c["Phone"], c["Fax"], c["Country"], c["ContactTitle"], c["ContactName"], c["CompanyName"], c["City"], c["Address"] FROM root c WHERE c["$type"] = "Customer" ) s """); }); @@ -99,7 +99,7 @@ public Task FromSqlRaw_queryable_simple_columns_out_of_order_and_extra_columns(b using var context = CreateContext(); var query = context.Set().FromSqlRaw( """ -SELECT c["id"], c["Discriminator"], c["Region"], c["PostalCode"], c["PostalCode"] AS Foo, c["Phone"], c["Fax"], c["Country"], c["ContactTitle"], c["ContactName"], c["CompanyName"], c["City"], c["Address"] FROM root c WHERE c["Discriminator"] = "Customer" +SELECT c["id"], c["$type"], c["Region"], c["PostalCode"], c["PostalCode"] AS Foo, c["Phone"], c["Fax"], c["Country"], c["ContactTitle"], c["ContactName"], c["CompanyName"], c["City"], c["Address"] FROM root c WHERE c["$type"] = "Customer" """); var actual = a @@ -113,7 +113,7 @@ public Task FromSqlRaw_queryable_simple_columns_out_of_order_and_extra_columns(b """ SELECT VALUE s FROM ( - SELECT c["id"], c["Discriminator"], c["Region"], c["PostalCode"], c["PostalCode"] AS Foo, c["Phone"], c["Fax"], c["Country"], c["ContactTitle"], c["ContactName"], c["CompanyName"], c["City"], c["Address"] FROM root c WHERE c["Discriminator"] = "Customer" + SELECT c["id"], c["$type"], c["Region"], c["PostalCode"], c["PostalCode"] AS Foo, c["Phone"], c["Fax"], c["Country"], c["ContactTitle"], c["ContactName"], c["CompanyName"], c["City"], c["Address"] FROM root c WHERE c["$type"] = "Customer" ) s """); }); @@ -126,7 +126,7 @@ public Task FromSqlRaw_queryable_composed(bool async) { using var context = CreateContext(); var query = context.Set().FromSqlRaw(""" - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" """) .Where(c => c.ContactName.Contains("z")); @@ -143,7 +143,7 @@ public Task FromSqlRaw_queryable_composed(bool async) """ SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" ) s WHERE CONTAINS(s["ContactName"], "z") """); @@ -157,7 +157,7 @@ public virtual Task FromSqlRaw_queryable_composed_after_removing_whitespaces(boo { using var context = CreateContext(); var query = context.Set().FromSqlRaw( - _eol + " " + _eol + _eol + _eol + "SELECT" + _eol + @"* FROM root c WHERE c[""Discriminator""] = ""Customer""") + _eol + " " + _eol + _eol + _eol + "SELECT" + _eol + @"* FROM root c WHERE c[""$type""] = ""Customer""") .Where(c => c.ContactName.Contains("z")); var actual = a @@ -177,7 +177,7 @@ SELECT VALUE s SELECT - * FROM root c WHERE c["Discriminator"] = "Customer" + * FROM root c WHERE c["$type"] = "Customer" ) s WHERE CONTAINS(s["ContactName"], "z") """); @@ -194,7 +194,7 @@ public Task FromSqlRaw_queryable_composed_compiled(bool async) var query = EF.CompileAsyncQuery( (NorthwindContext context) => context.Set() .FromSqlRaw(""" - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" """) .Where(c => c.ContactName.Contains("z"))); @@ -209,7 +209,7 @@ public Task FromSqlRaw_queryable_composed_compiled(bool async) { var query = EF.CompileQuery( (NorthwindContext context) => context.Set() - .FromSqlRaw("""SELECT * FROM root c WHERE c["Discriminator"] = "Customer" """) + .FromSqlRaw("""SELECT * FROM root c WHERE c["$type"] = "Customer" """) .Where(c => c.ContactName.Contains("z"))); using (var context = CreateContext()) @@ -224,7 +224,7 @@ public Task FromSqlRaw_queryable_composed_compiled(bool async) """ SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" ) s WHERE CONTAINS(s["ContactName"], "z") """); @@ -240,7 +240,7 @@ public virtual Task FromSqlRaw_queryable_composed_compiled_with_parameter(bool a { var query = EF.CompileAsyncQuery( (NorthwindContext context) => context.Set().FromSqlRaw( - """SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["id"] = {0}""", "CONSH") + """SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["id"] = {0}""", "CONSH") .Where(c => c.ContactName.Contains("z"))); using (var context = CreateContext()) @@ -254,7 +254,7 @@ public virtual Task FromSqlRaw_queryable_composed_compiled_with_parameter(bool a { var query = EF.CompileQuery( (NorthwindContext context) => context.Set().FromSqlRaw( - """SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["id"] = {0}""", "CONSH") + """SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["id"] = {0}""", "CONSH") .Where(c => c.ContactName.Contains("z"))); using (var context = CreateContext()) @@ -269,7 +269,7 @@ public virtual Task FromSqlRaw_queryable_composed_compiled_with_parameter(bool a """ SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["id"] = "CONSH" + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["id"] = "CONSH" ) s WHERE CONTAINS(s["ContactName"], "z") """); @@ -286,7 +286,7 @@ public virtual Task FromSqlRaw_queryable_multiple_line_query(bool async) """ SELECT * FROM root c -WHERE c["Discriminator"] = "Customer" AND c["City"] = 'London' +WHERE c["$type"] = "Customer" AND c["City"] = 'London' """); var actual = a @@ -302,7 +302,7 @@ SELECT VALUE s FROM ( SELECT * FROM root c - WHERE c["Discriminator"] = "Customer" AND c["City"] = 'London' + WHERE c["$type"] = "Customer" AND c["City"] = 'London' ) s """); }); @@ -318,7 +318,7 @@ public virtual Task FromSqlRaw_queryable_composed_multiple_line_query(bool async """ SELECT * FROM root c -WHERE c["Discriminator"] = "Customer" +WHERE c["$type"] = "Customer" """) .Where(c => c.City == "London"); @@ -335,7 +335,7 @@ SELECT VALUE s FROM ( SELECT * FROM root c - WHERE c["Discriminator"] = "Customer" + WHERE c["$type"] = "Customer" ) s WHERE (s["City"] = "London") """); @@ -352,7 +352,7 @@ public Task FromSqlRaw_queryable_with_parameters(bool async) using var context = CreateContext(); var query = context.Set().FromSqlRaw( - """SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = {0} AND c["ContactTitle"] = {1}""", + """SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = {0} AND c["ContactTitle"] = {1}""", city, contactTitle); @@ -371,7 +371,7 @@ public Task FromSqlRaw_queryable_with_parameters(bool async) SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = @p0 AND c["ContactTitle"] = @p1 + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = @p0 AND c["ContactTitle"] = @p1 ) s """); }); @@ -384,7 +384,7 @@ public Task FromSqlRaw_queryable_with_parameters_inline(bool async) { using var context = CreateContext(); var query = context.Set().FromSqlRaw( - """SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = {0} AND c["ContactTitle"] = {1}""", + """SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = {0} AND c["ContactTitle"] = {1}""", "London", "Sales Representative"); @@ -403,7 +403,7 @@ public Task FromSqlRaw_queryable_with_parameters_inline(bool async) SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = @p0 AND c["ContactTitle"] = @p1 + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = @p0 AND c["ContactTitle"] = @p1 ) s """); }); @@ -418,7 +418,7 @@ public Task FromSqlRaw_queryable_with_null_parameter(bool async) using var context = CreateContext(); var query = context.Set().FromSqlRaw( - """SELECT * FROM root c WHERE c["Discriminator"] = "Employee" AND c["ReportsTo"] = {0} OR (IS_NULL(c["ReportsTo"]) AND IS_NULL({0}))""", + """SELECT * FROM root c WHERE c["$type"] = "Employee" AND c["ReportsTo"] = {0} OR (IS_NULL(c["ReportsTo"]) AND IS_NULL({0}))""", reportsTo); var actual = a @@ -433,7 +433,7 @@ public Task FromSqlRaw_queryable_with_null_parameter(bool async) SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Employee" AND c["ReportsTo"] = @p0 OR (IS_NULL(c["ReportsTo"]) AND IS_NULL(@p0)) + SELECT * FROM root c WHERE c["$type"] = "Employee" AND c["ReportsTo"] = @p0 OR (IS_NULL(c["ReportsTo"]) AND IS_NULL(@p0)) ) s """); }); @@ -449,7 +449,7 @@ public Task FromSqlRaw_queryable_with_parameters_and_closure(bool async) using var context = CreateContext(); var query = context.Set().FromSqlRaw( - """SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = {0}""", city) + """SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = {0}""", city) .Where(c => c.ContactTitle == contactTitle); var queryString = query.ToQueryString(); @@ -468,7 +468,7 @@ public Task FromSqlRaw_queryable_with_parameters_and_closure(bool async) SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = @p0 + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = @p0 ) s WHERE (s["ContactTitle"] = @__contactTitle_1) """); @@ -482,7 +482,7 @@ public virtual Task FromSqlRaw_queryable_simple_cache_key_includes_query_string( { using var context = CreateContext(); var query = context.Set() - .FromSqlRaw("""SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = 'London'"""); + .FromSqlRaw("""SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = 'London'"""); var actual = a ? await query.ToArrayAsync() @@ -492,7 +492,7 @@ public virtual Task FromSqlRaw_queryable_simple_cache_key_includes_query_string( Assert.True(actual.All(c => c.City == "London")); query = context.Set() - .FromSqlRaw("""SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = 'Seattle'"""); + .FromSqlRaw("""SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = 'Seattle'"""); actual = a ? await query.ToArrayAsync() @@ -505,14 +505,14 @@ public virtual Task FromSqlRaw_queryable_simple_cache_key_includes_query_string( """ SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = 'London' + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = 'London' ) s """, // """ SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = 'Seattle' + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = 'Seattle' ) s """); }); @@ -526,7 +526,7 @@ public virtual Task FromSqlRaw_queryable_with_parameters_cache_key_includes_para var city = "London"; var contactTitle = "Sales Representative"; var sql = - """SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = {0} AND c["ContactTitle"] = {1}"""; + """SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = {0} AND c["ContactTitle"] = {1}"""; using var context = CreateContext(); var query = context.Set().FromSqlRaw(sql, city, contactTitle); @@ -559,7 +559,7 @@ public virtual Task FromSqlRaw_queryable_with_parameters_cache_key_includes_para SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = @p0 AND c["ContactTitle"] = @p1 + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = @p0 AND c["ContactTitle"] = @p1 ) s """, // @@ -569,7 +569,7 @@ SELECT VALUE s SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" AND c["City"] = @p0 AND c["ContactTitle"] = @p1 + SELECT * FROM root c WHERE c["$type"] = "Customer" AND c["City"] = @p0 AND c["ContactTitle"] = @p1 ) s """); }); @@ -582,7 +582,7 @@ public virtual Task FromSqlRaw_queryable_simple_as_no_tracking_not_composed(bool { using var context = CreateContext(); var query = context.Set().FromSqlRaw(""" - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" """) .AsNoTracking(); @@ -597,7 +597,7 @@ public virtual Task FromSqlRaw_queryable_simple_as_no_tracking_not_composed(bool """ SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" ) s """); }); @@ -613,7 +613,7 @@ public virtual Task FromSqlRaw_queryable_simple_projection_composed(bool async) """ SELECT * FROM root c -WHERE c["Discriminator"] = "Product" AND NOT c["Discontinued"] AND ((c["UnitsInStock"] + c["UnitsOnOrder"]) < c["ReorderLevel"]) +WHERE c["$type"] = "Product" AND NOT c["Discontinued"] AND ((c["UnitsInStock"] + c["UnitsOnOrder"]) < c["ReorderLevel"]) """) .Select(p => p.ProductName); @@ -629,7 +629,7 @@ SELECT VALUE s["ProductName"] FROM ( SELECT * FROM root c - WHERE c["Discriminator"] = "Product" AND NOT c["Discontinued"] AND ((c["UnitsInStock"] + c["UnitsOnOrder"]) < c["ReorderLevel"]) + WHERE c["$type"] = "Product" AND NOT c["Discontinued"] AND ((c["UnitsInStock"] + c["UnitsOnOrder"]) < c["ReorderLevel"]) ) s """); }); @@ -642,7 +642,7 @@ public virtual Task FromSqlRaw_composed_with_nullable_predicate(bool async) { using var context = CreateContext(); var query = context.Set().FromSqlRaw(""" - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" """) .Where(c => c.ContactName == c.CompanyName); @@ -656,7 +656,7 @@ public virtual Task FromSqlRaw_composed_with_nullable_predicate(bool async) """ SELECT VALUE s FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" ) s WHERE (s["ContactName"] = s["CompanyName"]) """); @@ -672,7 +672,7 @@ public virtual Task FromSqlRaw_does_not_parameterize_interpolated_string(bool as var propertyName = "OrderID"; var max = 10250; var query = context.Orders.FromSqlRaw( - $$"""SELECT * FROM root c WHERE c["Discriminator"] = "Order" AND c["{{propertyName}}"] < {0}""", max); + $$"""SELECT * FROM root c WHERE c["$type"] = "Order" AND c["{{propertyName}}"] < {0}""", max); var actual = a ? await query.ToListAsync() @@ -689,7 +689,7 @@ public virtual Task FromSqlRaw_queryable_simple_projection_not_composed(bool asy { using var context = CreateContext(); var query = context.Set().FromSqlRaw(""" - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" """) .Select( c => new { c.CustomerID, c.City }) @@ -710,7 +710,7 @@ SELECT VALUE "City" : s["City"] } FROM ( - SELECT * FROM root c WHERE c["Discriminator"] = "Customer" + SELECT * FROM root c WHERE c["$type"] = "Customer" ) s """); }); @@ -720,7 +720,7 @@ public async Task FromSqlRaw_queryable_simple_with_missing_key_and_non_tracking_ { using var context = CreateContext(); var query = context.Set() - .FromSqlRaw("""SELECT * FROM root c WHERE c["Discriminator"] = "Product" """) + .FromSqlRaw("""SELECT * FROM root c WHERE c["$type"] = "Product" """) .AsNoTracking(); var exception = await Assert.ThrowsAsync(() => query.ToArrayAsync()); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/InheritanceQueryCosmosFixture.cs b/test/EFCore.Cosmos.FunctionalTests/Query/InheritanceQueryCosmosFixture.cs index 4b0e4fa56cb..dd3ed72fb1c 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/InheritanceQueryCosmosFixture.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/InheritanceQueryCosmosFixture.cs @@ -34,6 +34,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity().ToContainer("Animals"); modelBuilder.Entity().ToContainer("Plants"); + modelBuilder.Entity().Property("Discriminator").ToJsonProperty("_type"); modelBuilder.Entity().ToContainer("Countries"); modelBuilder.Entity().ToContainer("Drinks");; modelBuilder.Entity().ToContainer("Animals"); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/InheritanceQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/InheritanceQueryCosmosTest.cs index 7c314bfd134..1a984168fcd 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/InheritanceQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/InheritanceQueryCosmosTest.cs @@ -16,6 +16,24 @@ public InheritanceQueryCosmosTest(InheritanceQueryCosmosFixture fixture, ITestOu //TestLoggerFactory.TestOutputHelper = testOutputHelper; } + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + public override async Task Filter_on_property_inside_complex_type_on_derived_type(bool async) + { + await base.Filter_on_property_inside_complex_type_on_derived_type(async); + + AssertSql(); + } + + public override async Task Using_OfType_on_multiple_type_with_no_result(bool async) + { + await base.Using_OfType_on_multiple_type_with_no_result(async); + + AssertSql(); + } + public override Task Can_query_when_shared_column(bool async) => Fixture.NoSyncTest( async, async a => @@ -242,7 +260,7 @@ public override Task Can_use_of_type_rose(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("Daisy", "Rose") AND (c["Discriminator"] = "Rose")) +WHERE (c["$type"] IN ("Daisy", "Rose") AND (c["$type"] = "Rose")) """); }); @@ -279,7 +297,7 @@ public override Task Can_query_all_plants(bool async) """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("Daisy", "Rose") +WHERE c["$type"] IN ("Daisy", "Rose") ORDER BY c["id"] """); }); @@ -339,7 +357,7 @@ public override Task Can_query_just_roses(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "Rose") +WHERE (c["$type"] = "Rose") OFFSET 0 LIMIT 2 """); }); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NonSharedPrimitiveCollectionsQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NonSharedPrimitiveCollectionsQueryCosmosTest.cs index ad94d693fd2..667ea4b454c 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NonSharedPrimitiveCollectionsQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NonSharedPrimitiveCollectionsQueryCosmosTest.cs @@ -358,7 +358,7 @@ public override async Task Project_collection_from_entity_type_with_owned() """ SELECT VALUE c["Ints"] FROM root c -WHERE (c["Discriminator"] = "TestEntityWithOwned") +WHERE (c["$type"] = "TestEntityWithOwned") """); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs index f5a09ab5977..7f285c08223 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs @@ -37,7 +37,7 @@ public override Task Average_over_default_returns_default(bool async) """ SELECT VALUE AVG((c["OrderID"] - 10248)) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 10248)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 10248)) """); }); @@ -103,19 +103,19 @@ public override Task Count_on_projection_with_client_eval(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """, // """ SELECT VALUE COUNT(1) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """, // """ SELECT VALUE COUNT(1) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -144,7 +144,7 @@ public override Task Max_over_default_returns_default(bool async) """ SELECT VALUE MAX((c["OrderID"] - 10248)) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 10248)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 10248)) """); }); @@ -158,7 +158,7 @@ public override Task Min_over_default_returns_default(bool async) """ SELECT VALUE MIN((c["OrderID"] - 10248)) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 10248)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 10248)) """); }); @@ -172,7 +172,7 @@ public override Task Sum_over_empty_returns_zero(bool async) """ SELECT VALUE SUM(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 42)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 42)) """); }); @@ -350,7 +350,7 @@ public override Task Sum_with_no_arg(bool async) """ SELECT VALUE SUM(c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -364,7 +364,7 @@ public override Task Sum_with_no_data_cast_to_nullable(bool async) """ SELECT VALUE SUM(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 0)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 0)) """); }); @@ -378,7 +378,7 @@ public override Task Sum_with_binary_expression(bool async) """ SELECT VALUE SUM((c["OrderID"] * 2)) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -392,7 +392,7 @@ public override Task Sum_with_no_arg_empty(bool async) """ SELECT VALUE SUM(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 42)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 42)) """); }); @@ -406,7 +406,7 @@ public override Task Sum_with_no_data_nullable(bool async) """ SELECT VALUE SUM(c["SupplierID"]) FROM root c -WHERE (c["Discriminator"] = "Product") +WHERE (c["$type"] = "Product") """); }); @@ -420,7 +420,7 @@ public override Task Sum_with_arg(bool async) """ SELECT VALUE SUM(c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -434,7 +434,7 @@ public override Task Sum_with_arg_expression(bool async) """ SELECT VALUE SUM((c["OrderID"] + c["OrderID"])) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -465,7 +465,7 @@ public override Task Sum_with_coalesce(bool async) """ SELECT VALUE SUM(((c["UnitPrice"] != null) ? c["UnitPrice"] : 0.0)) FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["ProductID"] < 40)) +WHERE ((c["$type"] = "Product") AND (c["ProductID"] < 40)) """); }); @@ -527,7 +527,7 @@ public override Task Sum_on_float_column(bool async) """ SELECT VALUE SUM(c["Discount"]) FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND (c["ProductID"] = 1)) +WHERE ((c["$type"] = "OrderDetail") AND (c["ProductID"] = 1)) """); }); @@ -550,7 +550,7 @@ public override async Task Average_no_data(bool async) """ SELECT VALUE AVG(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = -1)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = -1)) """); } } @@ -571,7 +571,7 @@ await Fixture.NoSyncTest( """ SELECT VALUE AVG(c["SupplierID"]) FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["SupplierID"] = -1)) +WHERE ((c["$type"] = "Product") AND (c["SupplierID"] = -1)) """); }); } @@ -593,7 +593,7 @@ await Fixture.NoSyncTest( """ SELECT VALUE AVG(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = -1)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = -1)) """); }); } @@ -610,7 +610,7 @@ public override async Task Min_no_data(bool async) """ SELECT VALUE MIN(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = -1)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = -1)) """); } } @@ -626,7 +626,7 @@ public override async Task Max_no_data(bool async) """ SELECT VALUE MAX(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = -1)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = -1)) """); } } @@ -663,7 +663,7 @@ await Fixture.NoSyncTest( """ SELECT VALUE MAX(c["SupplierID"]) FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["SupplierID"] = -1)) +WHERE ((c["$type"] = "Product") AND (c["SupplierID"] = -1)) """); }); } @@ -685,7 +685,7 @@ await Fixture.NoSyncTest( """ SELECT VALUE MAX(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = -1)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = -1)) """); }); } @@ -711,7 +711,7 @@ public override async Task Average_with_no_arg(bool async) """ SELECT VALUE AVG(c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); } } @@ -726,7 +726,7 @@ public override Task Average_with_binary_expression(bool async) """ SELECT VALUE AVG((c["OrderID"] * 2)) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -742,7 +742,7 @@ public override async Task Average_with_arg(bool async) """ SELECT VALUE AVG(c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); } } @@ -757,7 +757,7 @@ public override Task Average_with_arg_expression(bool async) """ SELECT VALUE AVG((c["OrderID"] + c["OrderID"])) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -788,7 +788,7 @@ public override Task Average_with_coalesce(bool async) """ SELECT VALUE AVG(((c["UnitPrice"] != null) ? c["UnitPrice"] : 0.0)) FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["ProductID"] < 40)) +WHERE ((c["$type"] = "Product") AND (c["ProductID"] < 40)) """); }); @@ -826,7 +826,7 @@ public override Task Average_on_float_column(bool async) """ SELECT VALUE AVG(c["Discount"]) FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND (c["ProductID"] = 1)) +WHERE ((c["$type"] = "OrderDetail") AND (c["ProductID"] = 1)) """); }); @@ -856,7 +856,7 @@ public override Task Min_with_no_arg(bool async) """ SELECT VALUE MIN(c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -870,7 +870,7 @@ public override Task Min_with_arg(bool async) """ SELECT VALUE MIN(c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -890,7 +890,7 @@ await Fixture.NoSyncTest( """ SELECT VALUE MIN(c["SupplierID"]) FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["SupplierID"] = -1)) +WHERE ((c["$type"] = "Product") AND (c["SupplierID"] = -1)) """); }); } @@ -912,7 +912,7 @@ await Fixture.NoSyncTest( """ SELECT VALUE MIN(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = -1)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = -1)) """); }); } @@ -928,7 +928,7 @@ public override Task Min_with_coalesce(bool async) """ SELECT VALUE MIN(((c["UnitPrice"] != null) ? c["UnitPrice"] : 0.0)) FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["ProductID"] < 40)) +WHERE ((c["$type"] = "Product") AND (c["ProductID"] < 40)) """); }); @@ -966,7 +966,7 @@ public override Task Max_with_no_arg(bool async) """ SELECT VALUE MAX(c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -980,7 +980,7 @@ public override Task Max_with_arg(bool async) """ SELECT VALUE MAX(c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -994,7 +994,7 @@ public override Task Max_with_coalesce(bool async) """ SELECT VALUE MAX(((c["UnitPrice"] != null) ? c["UnitPrice"] : 0.0)) FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["ProductID"] < 40)) +WHERE ((c["$type"] = "Product") AND (c["ProductID"] < 40)) """); }); @@ -1032,7 +1032,7 @@ public override Task Count_with_no_predicate(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1046,7 +1046,7 @@ public override Task Count_with_predicate(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) """); }); @@ -1060,7 +1060,7 @@ public override Task Count_with_order_by(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1074,7 +1074,7 @@ public override Task Where_OrderBy_Count(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) """); }); @@ -1088,7 +1088,7 @@ public override Task OrderBy_Where_Count(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) """); }); @@ -1102,7 +1102,7 @@ public override Task OrderBy_Count_with_predicate(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) """); }); @@ -1116,7 +1116,7 @@ public override Task OrderBy_Where_Count_with_predicate(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE (((c["Discriminator"] = "Order") AND (c["OrderID"] > 10)) AND (c["CustomerID"] != "ALFKI")) +WHERE (((c["$type"] = "Order") AND (c["OrderID"] > 10)) AND (c["CustomerID"] != "ALFKI")) """); }); @@ -1229,7 +1229,7 @@ public override Task Distinct_Scalar(bool async) """ SELECT DISTINCT c[""City""] FROM root c -WHERE (c[""Discriminator""] = ""Customer"") +WHERE (c[""$type""] = ""Customer"") """); }); @@ -1244,7 +1244,7 @@ public override Task OrderBy_Distinct(bool async) """ SELECT DISTINCT c["City"] FROM root c -WHERE (c["Discriminator"] = "Customer") +WHERE (c["$type"] = "Customer") ORDER BY c["id"] """); }); @@ -2206,7 +2206,7 @@ public override Task Contains_with_parameter_list_value_type_id(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND c["OrderID"] IN (10248, 10249)) +WHERE ((c["$type"] = "Order") AND c["OrderID"] IN (10248, 10249)) """); }); @@ -2220,7 +2220,7 @@ public override Task Contains_with_constant_list_value_type_id(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND c["OrderID"] IN (10248, 10249)) +WHERE ((c["$type"] = "Order") AND c["OrderID"] IN (10248, 10249)) """); }); @@ -2302,7 +2302,7 @@ public override async Task Contains_over_entityType_with_null_should_rewrite_to_ SELECT VALUE EXISTS ( SELECT 1 FROM root c - WHERE (((c["Discriminator"] = "Order") AND (c["CustomerID"] = "VINET")) AND (c["OrderID"] = @__entity_equality_p_0_OrderID))) + WHERE (((c["$type"] = "Order") AND (c["CustomerID"] = "VINET")) AND (c["OrderID"] = @__entity_equality_p_0_OrderID))) """); } } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindDbFunctionsQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindDbFunctionsQueryCosmosTest.cs index 22679641139..39832d51071 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindDbFunctionsQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindDbFunctionsQueryCosmosTest.cs @@ -64,7 +64,7 @@ public override Task Random_return_less_than_1(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (RAND() < 1.0)) +WHERE ((c["$type"] = "Order") AND (RAND() < 1.0)) """); }); @@ -78,7 +78,7 @@ public override Task Random_return_greater_than_0(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (RAND() >= 0.0)) +WHERE ((c["$type"] = "Order") AND (RAND() >= 0.0)) """); }); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs index c5783af4006..dc76fc9e20e 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs @@ -480,7 +480,7 @@ public override Task Where_math_abs1(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (ABS(c["ProductID"]) > 10)) +WHERE ((c["$type"] = "Product") AND (ABS(c["ProductID"]) > 10)) """); }); @@ -494,7 +494,7 @@ public override Task Where_math_abs2(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["UnitPrice"] < 7.0)) AND (ABS(c["Quantity"]) > 10)) +WHERE (((c["$type"] = "OrderDetail") AND (c["UnitPrice"] < 7.0)) AND (ABS(c["Quantity"]) > 10)) """); }); @@ -508,7 +508,7 @@ public override Task Where_math_abs3(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (ABS(c["UnitPrice"]) > 10.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (ABS(c["UnitPrice"]) > 10.0)) """); }); @@ -522,7 +522,7 @@ public override Task Where_math_abs_uncorrelated(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["UnitPrice"] < 7.0)) AND (10 < c["ProductID"])) +WHERE (((c["$type"] = "OrderDetail") AND (c["UnitPrice"] < 7.0)) AND (10 < c["ProductID"])) """); }); @@ -544,7 +544,7 @@ public override Task Where_math_ceiling2(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (CEILING(c["UnitPrice"]) > 10.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (CEILING(c["UnitPrice"]) > 10.0)) """); }); @@ -558,7 +558,7 @@ public override Task Where_math_floor(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (FLOOR(c["UnitPrice"]) > 10.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (FLOOR(c["UnitPrice"]) > 10.0)) """); }); @@ -588,7 +588,7 @@ public override Task Where_math_round(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (ROUND(c["UnitPrice"]) > 10.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (ROUND(c["UnitPrice"]) > 10.0)) """); }); @@ -614,7 +614,7 @@ public override Task Select_math_round_int(bool async) """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10250)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10250)) """); }); @@ -628,7 +628,7 @@ public override Task Select_math_truncate_int(bool async) """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10250)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10250)) """); }); @@ -650,7 +650,7 @@ public override Task Where_math_truncate(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (TRUNC(c["UnitPrice"]) > 10.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["Quantity"] < 5)) AND (TRUNC(c["UnitPrice"]) > 10.0)) """); }); @@ -760,7 +760,7 @@ public override Task Where_math_sign(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (SIGN(c["Discount"]) > 0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (SIGN(c["Discount"]) > 0)) """); }); @@ -846,7 +846,7 @@ public override Task Where_mathf_ceiling1(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["UnitPrice"] < 7.0)) AND (CEILING(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["UnitPrice"] < 7.0)) AND (CEILING(c["Discount"]) > 0.0)) """); }); @@ -868,7 +868,7 @@ public override Task Where_mathf_power(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND (POWER(c["Discount"], 3.0) > 0.005)) +WHERE ((c["$type"] = "OrderDetail") AND (POWER(c["Discount"], 3.0) > 0.005)) """); }); @@ -882,7 +882,7 @@ public override Task Where_mathf_square(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND (POWER(c["Discount"], 2.0) > 0.05)) +WHERE ((c["$type"] = "OrderDetail") AND (POWER(c["Discount"], 2.0) > 0.05)) """); }); @@ -912,7 +912,7 @@ public override Task Where_mathf_exp(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (EXP(c["Discount"]) > 1.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (EXP(c["Discount"]) > 1.0)) """); }); @@ -926,7 +926,7 @@ public override Task Where_mathf_log10(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND ((c["OrderID"] = 11077) AND (c["Discount"] > 0.0))) AND (LOG10(c["Discount"]) < 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND ((c["OrderID"] = 11077) AND (c["Discount"] > 0.0))) AND (LOG10(c["Discount"]) < 0.0)) """); }); @@ -940,7 +940,7 @@ public override Task Where_mathf_log(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND ((c["OrderID"] = 11077) AND (c["Discount"] > 0.0))) AND (LOG(c["Discount"]) < 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND ((c["OrderID"] = 11077) AND (c["Discount"] > 0.0))) AND (LOG(c["Discount"]) < 0.0)) """); }); @@ -954,7 +954,7 @@ public override Task Where_mathf_log_new_base(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND ((c["OrderID"] = 11077) AND (c["Discount"] > 0.0))) AND (LOG(c["Discount"], 7.0) < -1.0)) +WHERE (((c["$type"] = "OrderDetail") AND ((c["OrderID"] = 11077) AND (c["Discount"] > 0.0))) AND (LOG(c["Discount"], 7.0) < -1.0)) """); }); @@ -968,7 +968,7 @@ public override Task Where_mathf_sqrt(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (SQRT(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (SQRT(c["Discount"]) > 0.0)) """); }); @@ -982,7 +982,7 @@ public override Task Where_mathf_acos(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (ACOS(c["Discount"]) > 1.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (ACOS(c["Discount"]) > 1.0)) """); }); @@ -996,7 +996,7 @@ public override Task Where_mathf_asin(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (ASIN(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (ASIN(c["Discount"]) > 0.0)) """); }); @@ -1010,7 +1010,7 @@ public override Task Where_mathf_atan(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (ATAN(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (ATAN(c["Discount"]) > 0.0)) """); }); @@ -1024,7 +1024,7 @@ public override Task Where_mathf_atan2(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (ATN2(c["Discount"], 1.0) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (ATN2(c["Discount"], 1.0) > 0.0)) """); }); @@ -1038,7 +1038,7 @@ public override Task Where_mathf_cos(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (COS(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (COS(c["Discount"]) > 0.0)) """); }); @@ -1052,7 +1052,7 @@ public override Task Where_mathf_sin(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (SIN(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (SIN(c["Discount"]) > 0.0)) """); }); @@ -1066,7 +1066,7 @@ public override Task Where_mathf_tan(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (TAN(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (TAN(c["Discount"]) > 0.0)) """); }); @@ -1080,7 +1080,7 @@ public override Task Where_mathf_sign(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (SIGN(c["Discount"]) > 0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (SIGN(c["Discount"]) > 0)) """); }); @@ -1094,7 +1094,7 @@ public override Task Where_mathf_degrees(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (DEGREES(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (DEGREES(c["Discount"]) > 0.0)) """); }); @@ -1108,7 +1108,7 @@ public override Task Where_mathf_radians(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (RADIANS(c["Discount"]) > 0.0)) +WHERE (((c["$type"] = "OrderDetail") AND (c["OrderID"] = 11077)) AND (RADIANS(c["Discount"]) > 0.0)) """); }); @@ -1633,7 +1633,7 @@ public override Task Static_equals_nullable_datetime_compared_to_non_nullable(bo SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] = @__arg_0)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] = @__arg_0)) """); }); @@ -1973,7 +1973,7 @@ public override Task Select_mathf_round(bool async) """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10250)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10250)) """); }); @@ -1987,7 +1987,7 @@ public override Task Select_mathf_round2(bool async) """ SELECT VALUE c["UnitPrice"] FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND (c["Quantity"] < 5)) +WHERE ((c["$type"] = "OrderDetail") AND (c["Quantity"] < 5)) """); }); @@ -2001,7 +2001,7 @@ public override Task Select_mathf_truncate(bool async) """ SELECT VALUE c["UnitPrice"] FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND (c["Quantity"] < 5)) +WHERE ((c["$type"] = "OrderDetail") AND (c["Quantity"] < 5)) """); }); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindKeylessEntitiesQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindKeylessEntitiesQueryCosmosTest.cs index ba975f59dbc..4b29b445211 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindKeylessEntitiesQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindKeylessEntitiesQueryCosmosTest.cs @@ -62,7 +62,7 @@ await Assert.ThrowsAsync( """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "ProductView") +WHERE (c["$type"] = "ProductView") """); } } @@ -118,7 +118,7 @@ public override Task KeylessEntity_with_defining_query(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) """); }); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs index 55a16f3ebd4..784da8c75ae 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs @@ -495,7 +495,7 @@ await Assert.ThrowsAsync( """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "Product") +WHERE (c["$type"] = "Product") ORDER BY (c["UnitsInStock"] > 0), c["ProductID"] """); } @@ -514,7 +514,7 @@ await Assert.ThrowsAsync( """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "Product") +WHERE (c["$type"] = "Product") ORDER BY ((c["UnitsInStock"] > 10) ? (c["ProductID"] > 40) : (c["ProductID"] <= 40)), c["ProductID"] """); } @@ -1576,7 +1576,7 @@ public override Task Select_DTO_distinct_translated_to_server(bool async) """ SELECT DISTINCT 1 FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10300)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10300)) """); }); @@ -1590,7 +1590,7 @@ public override Task Select_DTO_constructor_distinct_translated_to_server(bool a """ SELECT DISTINCT VALUE c["CustomerID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10300)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10300)) """); }); @@ -1608,7 +1608,7 @@ SELECT DISTINCT VALUE "Count" : c["OrderID"] } FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10300)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10300)) """); }); @@ -1901,7 +1901,7 @@ public override Task DateTime_parse_is_inlined(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] > "1998-01-01T12:00:00")) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] > "1998-01-01T12:00:00")) """); }); @@ -1917,7 +1917,7 @@ public override Task DateTime_parse_is_parameterized_when_from_closure(bool asyn SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] > @__Parse_0)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] > @__Parse_0)) """); }); @@ -1931,7 +1931,7 @@ public override Task New_DateTime_is_inlined(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] > "1998-01-01T12:00:00")) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] > "1998-01-01T12:00:00")) """); }); @@ -1947,7 +1947,7 @@ public override Task New_DateTime_is_parameterized_when_from_closure(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] > @__p_0)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] > @__p_0)) """, // """ @@ -1955,7 +1955,7 @@ FROM root c SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] > @__p_0)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] > @__p_0)) """); }); @@ -2192,7 +2192,7 @@ public override Task Where_bitwise_binary_not(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (~(c["OrderID"]) = @__negatedId_0)) +WHERE ((c["$type"] = "Order") AND (~(c["OrderID"]) = @__negatedId_0)) """); }); @@ -2206,7 +2206,7 @@ public override Task Where_bitwise_binary_and(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] & 10248) = 10248)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] & 10248) = 10248)) """); }); @@ -2220,7 +2220,7 @@ public override Task Where_bitwise_binary_or(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] | 10248) = 10248)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] | 10248) = 10248)) """); }); @@ -2234,7 +2234,7 @@ public override Task Where_bitwise_binary_xor(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] ^ 1) = 10249)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] ^ 1) = 10249)) """); }); @@ -2300,13 +2300,13 @@ public override Task Parameter_extraction_short_circuits_1(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] < 10400) AND (((c["OrderDate"] != null) AND (DateTimePart("mm", c["OrderDate"]) = @__dateFilter_Value_Month_0)) AND (DateTimePart("yyyy", c["OrderDate"]) = @__dateFilter_Value_Year_1)))) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] < 10400) AND (((c["OrderDate"] != null) AND (DateTimePart("mm", c["OrderDate"]) = @__dateFilter_Value_Month_0)) AND (DateTimePart("yyyy", c["OrderDate"]) = @__dateFilter_Value_Year_1)))) """, // """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10400)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10400)) """); }); @@ -2324,7 +2324,7 @@ public override Task Parameter_extraction_short_circuits_2(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] < 10400) AND (((c["OrderDate"] != null) AND (DateTimePart("mm", c["OrderDate"]) = @__dateFilter_Value_Month_0)) AND (DateTimePart("yyyy", c["OrderDate"]) = @__dateFilter_Value_Year_1)))) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] < 10400) AND (((c["OrderDate"] != null) AND (DateTimePart("mm", c["OrderDate"]) = @__dateFilter_Value_Month_0)) AND (DateTimePart("yyyy", c["OrderDate"]) = @__dateFilter_Value_Year_1)))) """, // """ @@ -2348,13 +2348,13 @@ public override Task Parameter_extraction_short_circuits_3(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] < 10400) OR (((c["OrderDate"] != null) AND (DateTimePart("mm", c["OrderDate"]) = @__dateFilter_Value_Month_0)) AND (DateTimePart("yyyy", c["OrderDate"]) = @__dateFilter_Value_Year_1)))) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] < 10400) OR (((c["OrderDate"] != null) AND (DateTimePart("mm", c["OrderDate"]) = @__dateFilter_Value_Month_0)) AND (DateTimePart("yyyy", c["OrderDate"]) = @__dateFilter_Value_Year_1)))) """, // """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -2384,7 +2384,7 @@ public override Task Select_expression_long_to_string(bool async) """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2398,7 +2398,7 @@ public override Task Select_expression_int_to_string(bool async) """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2412,13 +2412,13 @@ public override Task ToString_with_formatter_is_evaluated_on_the_client(bool asy """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """, // """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2432,7 +2432,7 @@ public override Task Select_expression_other_to_string(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2446,7 +2446,7 @@ public override Task Select_expression_date_add_year(bool async) """ SELECT VALUE DateTimeAdd("yyyy", 1, c["OrderDate"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2460,7 +2460,7 @@ public override Task Select_expression_datetime_add_month(bool async) """ SELECT VALUE DateTimeAdd("mm", 1, c["OrderDate"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2474,7 +2474,7 @@ public override Task Select_expression_datetime_add_hour(bool async) """ SELECT VALUE DateTimeAdd("hh", 1.0, c["OrderDate"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2488,7 +2488,7 @@ public override Task Select_expression_datetime_add_minute(bool async) """ SELECT VALUE DateTimeAdd("mi", 1.0, c["OrderDate"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2502,7 +2502,7 @@ public override Task Select_expression_datetime_add_second(bool async) """ SELECT VALUE DateTimeAdd("ss", 1.0, c["OrderDate"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2516,7 +2516,7 @@ public override Task Select_expression_date_add_milliseconds_above_the_range(boo """ SELECT VALUE DateTimeAdd("ms", 1000000000000.0, c["OrderDate"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2530,7 +2530,7 @@ public override Task Select_expression_date_add_milliseconds_below_the_range(boo """ SELECT VALUE DateTimeAdd("ms", -1000000000000.0, c["OrderDate"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2544,7 +2544,7 @@ public override Task Select_expression_date_add_milliseconds_large_number_divide """ SELECT c["OrderDate"], DateTimePart("ms", c["OrderDate"]) AS c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -2558,7 +2558,7 @@ public override Task Add_minutes_on_constant_value(bool async) """ SELECT VALUE (c["OrderID"] % 25) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10500)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10500)) ORDER BY c["OrderID"] """); }); @@ -2575,7 +2575,7 @@ public override Task Select_expression_references_are_updated_correctly_with_sub SELECT DISTINCT VALUE DateTimePart("yyyy", c["OrderDate"]) FROM root c -WHERE (((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) AND (DateTimePart("yyyy", c["OrderDate"]) < @__nextYear_0)) +WHERE (((c["$type"] = "Order") AND (c["OrderDate"] != null)) AND (DateTimePart("yyyy", c["OrderDate"]) < @__nextYear_0)) """); }); @@ -3535,7 +3535,7 @@ await Assert.ThrowsAsync( """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "OrderDetail") +WHERE (c["$type"] = "OrderDetail") ORDER BY c["OrderID"] DESC, c["ProductID"] DESC """); } @@ -3949,7 +3949,7 @@ public override Task Checked_context_with_arithmetic_does_not_fail(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND ((((c["Quantity"] + 1) = 5) AND ((c["Quantity"] - 1) = 3)) AND ((c["Quantity"] * 1) = c["Quantity"]))) +WHERE ((c["$type"] = "OrderDetail") AND ((((c["Quantity"] + 1) = 5) AND ((c["Quantity"] - 1) = 3)) AND ((c["Quantity"] * 1) = c["Quantity"]))) ORDER BY c["OrderID"] """); }); @@ -3964,7 +3964,7 @@ public override Task Checked_context_with_case_to_same_nullable_type_does_not_fa """ SELECT VALUE MAX(c["Quantity"]) FROM root c -WHERE (c["Discriminator"] = "OrderDetail") +WHERE (c["$type"] = "OrderDetail") """); }); @@ -4202,7 +4202,7 @@ public override Task Select_Property_when_non_shadow(bool async) """ SELECT VALUE c["OrderID"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -4241,7 +4241,7 @@ public override Task Concat_int_string(bool async) """ SELECT c["CustomerID"], c["OrderID"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -4255,7 +4255,7 @@ public override Task Select_expression_datetime_add_ticks(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderDate"] != null)) +WHERE ((c["$type"] = "Order") AND (c["OrderDate"] != null)) """); }); @@ -4296,7 +4296,7 @@ public override Task Concat_constant_string_int(bool async) """ SELECT VALUE c["OrderID"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -4346,7 +4346,7 @@ public override Task Concat_string_int(bool async) """ SELECT c["OrderID"], c["CustomerID"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -4391,7 +4391,7 @@ public override Task Entity_equality_not_null_composite_key(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND ((c["OrderID"] != null) AND (c["ProductID"] != null))) +WHERE ((c["$type"] = "OrderDetail") AND ((c["OrderID"] != null) AND (c["ProductID"] != null))) """); }); @@ -4541,7 +4541,7 @@ public override Task Entity_equality_null_composite_key(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "OrderDetail") AND ((c["OrderID"] = null) OR (c["ProductID"] = null))) +WHERE ((c["$type"] = "OrderDetail") AND ((c["OrderID"] = null) OR (c["ProductID"] = null))) """); }); @@ -4555,7 +4555,7 @@ public override Task Concat_parameter_string_int(bool async) """ SELECT VALUE c["OrderID"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -4602,7 +4602,7 @@ public override Task Convert_to_nullable_on_nullable_value_is_ignored(bool async """ SELECT VALUE c["OrderDate"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -4616,7 +4616,7 @@ public override Task Ternary_should_not_evaluate_both_sides_with_parameter(bool """ SELECT VALUE true FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindQueryCosmosFixture.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindQueryCosmosFixture.cs index 1576130227b..9ea50d1c564 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindQueryCosmosFixture.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindQueryCosmosFixture.cs @@ -55,29 +55,29 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity() .ToContainer("ProductsAndOrders") .IncludeRootDiscriminatorInJsonId() - .HasDiscriminator("Discriminator").HasValue("Order"); + .HasDiscriminator("$type").HasValue("Order"); modelBuilder .Entity() .ToContainer("ProductsAndOrders") .IncludeRootDiscriminatorInJsonId() - .HasDiscriminator("Discriminator").HasValue("Product"); + .HasDiscriminator("$type").HasValue("Product"); modelBuilder .Entity() .ToContainer("ProductsAndOrders") .IncludeRootDiscriminatorInJsonId() - .HasDiscriminator("Discriminator").HasValue("ProductView"); + .HasDiscriminator("$type").HasValue("ProductView"); modelBuilder .Entity() .ToContainer("Customers") - .HasDiscriminator("Discriminator").HasValue("Customer"); + .HasDiscriminator("$type").HasValue("Customer"); modelBuilder .Entity() .ToContainer("Customers") - .HasDiscriminator("Discriminator").HasValue("Customer"); + .HasDiscriminator("$type").HasValue("Customer"); modelBuilder.Entity().Metadata.RemoveIndex( modelBuilder.Entity().Property(e => e.City).Metadata.GetContainingIndexes().Single()); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs index bdc2ae2f481..0a268f9aec9 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs @@ -40,7 +40,7 @@ await AssertQuery( """ SELECT VALUE c["OrderID"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -58,7 +58,7 @@ SELECT VALUE "B" : ((c["OrderID"] / c["OrderID"]) / 2) } FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -81,7 +81,7 @@ SELECT VALUE "o" : c } FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -310,7 +310,7 @@ SELECT VALUE "IsAvailable" : (c["UnitsInStock"] > 0) } FROM root c -WHERE (c["Discriminator"] = "Product") +WHERE (c["$type"] = "Product") """); }); @@ -496,7 +496,7 @@ public override Task Select_non_matching_value_types_int_to_long_introduces_expl """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -511,7 +511,7 @@ public override Task Select_non_matching_value_types_nullable_int_to_long_introd """ SELECT VALUE c["EmployeeID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -526,7 +526,7 @@ public override Task Select_non_matching_value_types_nullable_int_to_int_doesnt_ """ SELECT VALUE c["EmployeeID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -541,7 +541,7 @@ public override Task Select_non_matching_value_types_int_to_nullable_int_doesnt_ """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -556,7 +556,7 @@ public override Task Select_non_matching_value_types_from_binary_expression_intr """ SELECT VALUE (c["OrderID"] + c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -572,7 +572,7 @@ public override Task Select_non_matching_value_types_from_binary_expression_nest """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -587,7 +587,7 @@ public override Task Select_non_matching_value_types_from_unary_expression_intro """ SELECT VALUE -(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -602,7 +602,7 @@ public override Task Select_non_matching_value_types_from_unary_expression_intro """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -617,7 +617,7 @@ public override Task Select_non_matching_value_types_from_length_introduces_expl """ SELECT VALUE LENGTH(c["CustomerID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -632,7 +632,7 @@ public override Task Select_non_matching_value_types_from_method_call_introduces """ SELECT VALUE ABS(c["OrderID"]) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -647,7 +647,7 @@ public override Task Select_non_matching_value_types_from_anonymous_type_introdu """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) ORDER BY c["OrderID"] """); }); @@ -673,7 +673,7 @@ public override Task Select_conditional_with_null_comparison_in_test(bool async) """ SELECT VALUE ((c["CustomerID"] = null) ? true : (c["OrderID"] < 100)) FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "ALFKI")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "ALFKI")) """); }); @@ -791,7 +791,7 @@ public override Task Select_datetime_year_component(bool async) """ SELECT VALUE DateTimePart("yyyy", c["OrderDate"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -805,7 +805,7 @@ public override Task Select_datetime_month_component(bool async) """ SELECT VALUE DateTimePart("mm", c["OrderDate"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -820,7 +820,7 @@ public override Task Select_datetime_day_of_year_component(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -834,7 +834,7 @@ public override Task Select_datetime_day_component(bool async) """ SELECT VALUE DateTimePart("dd", c["OrderDate"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -848,7 +848,7 @@ public override Task Select_datetime_hour_component(bool async) """ SELECT VALUE DateTimePart("hh", c["OrderDate"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -862,7 +862,7 @@ public override Task Select_datetime_minute_component(bool async) """ SELECT VALUE DateTimePart("mi", c["OrderDate"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -876,7 +876,7 @@ public override Task Select_datetime_second_component(bool async) """ SELECT VALUE DateTimePart("ss", c["OrderDate"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -890,7 +890,7 @@ public override Task Select_datetime_millisecond_component(bool async) """ SELECT VALUE DateTimePart("ms", c["OrderDate"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -943,7 +943,7 @@ public override Task Anonymous_projection_AsNoTracking_Selector(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -978,7 +978,7 @@ public override Task Select_GetValueOrDefault_on_DateTime(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1174,7 +1174,7 @@ SELECT VALUE "c" : (c["OrderID"] + 1000) } FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 10250)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 10250)) """); }); @@ -1236,7 +1236,7 @@ public override Task Coalesce_over_nullable_uint(bool async) """ SELECT VALUE ((c["EmployeeID"] != null) ? c["EmployeeID"] : 0) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1490,7 +1490,7 @@ SELECT VALUE "c1" : ((c["OrderDate"] != null) = false) } FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] < 10300)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] < 10300)) ORDER BY c["OrderID"] """); }); @@ -1716,7 +1716,7 @@ public override Task Select_datetime_DayOfWeek_component(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1761,7 +1761,7 @@ public override Task Projecting_nullable_struct(bool async) """ SELECT c["CustomerID"], (c["CustomerID"] = "ALFKI") AS c, c["OrderID"], LENGTH(c["CustomerID"]) AS c0 FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1815,7 +1815,7 @@ public override Task Cast_on_top_level_projection_brings_explicit_Cast(bool asyn """ SELECT VALUE c["OrderID"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1881,7 +1881,7 @@ public override Task Select_datetime_TimeOfDay_component(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1912,7 +1912,7 @@ public override Task Select_datetime_Ticks_component(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1964,7 +1964,7 @@ public override Task Select_conditional_drops_false(bool async) """ SELECT VALUE (((c["OrderID"] % 2) = 0) ? c["OrderID"] : -(c["OrderID"])) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1978,7 +1978,7 @@ public override Task Select_conditional_terminates_at_true(bool async) """ SELECT VALUE (((c["OrderID"] % 2) = 0) ? c["OrderID"] : 0) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -1992,7 +1992,7 @@ public override Task Select_conditional_flatten_nested_results(bool async) """ SELECT VALUE (((c["OrderID"] % 2) = 0) ? (((c["OrderID"] % 5) = 0) ? -(c["OrderID"]) : c["OrderID"]) : c["OrderID"]) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -2006,7 +2006,7 @@ public override Task Select_conditional_flatten_nested_tests(bool async) """ SELECT VALUE ((((c["OrderID"] % 2) = 0) ? false : true) ? c["OrderID"] : -(c["OrderID"])) FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs index ddef6a3fb7c..462d9fdbc14 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs @@ -39,7 +39,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] + 10) = 10258)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] + 10) = 10258)) """); }); @@ -57,7 +57,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] - 10) = 10238)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] - 10) = 10238)) """); }); @@ -75,7 +75,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] * 1) = 10248)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] * 1) = 10248)) """); }); @@ -93,7 +93,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] / 1) = 10248)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] / 1) = 10248)) """); }); @@ -111,7 +111,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] % 10248) = 0)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] % 10248) = 0)) """); }); @@ -180,7 +180,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] << 1) = 20496)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] << 1) = 20496)) """); }); @@ -198,7 +198,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ((c["OrderID"] >> 1) = 5124)) +WHERE ((c["$type"] = "Order") AND ((c["OrderID"] >> 1) = 5124)) """); }); @@ -396,7 +396,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (-(c["OrderID"]) = -10248)) +WHERE ((c["$type"] = "Order") AND (-(c["OrderID"]) = -10248)) """); }); @@ -414,7 +414,7 @@ await AssertQuery( """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (~(c["OrderID"]) = -10249)) +WHERE ((c["$type"] = "Order") AND (~(c["OrderID"]) = -10249)) """); }); @@ -1269,7 +1269,7 @@ public override Task Where_date_add_year_constant_component(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (DateTimePart("yyyy", DateTimeAdd("yyyy", -1, c["OrderDate"])) = 1997)) +WHERE ((c["$type"] = "Order") AND (DateTimePart("yyyy", DateTimeAdd("yyyy", -1, c["OrderDate"])) = 1997)) """); }); @@ -1283,7 +1283,7 @@ public override Task Where_datetime_year_component(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (DateTimePart("yyyy", c["OrderDate"]) = 1998)) +WHERE ((c["$type"] = "Order") AND (DateTimePart("yyyy", c["OrderDate"]) = 1998)) """); }); @@ -1297,7 +1297,7 @@ public override Task Where_datetime_month_component(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (DateTimePart("mm", c["OrderDate"]) = 4)) +WHERE ((c["$type"] = "Order") AND (DateTimePart("mm", c["OrderDate"]) = 4)) """); }); @@ -1319,7 +1319,7 @@ public override Task Where_datetime_day_component(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (DateTimePart("dd", c["OrderDate"]) = 4)) +WHERE ((c["$type"] = "Order") AND (DateTimePart("dd", c["OrderDate"]) = 4)) """); }); @@ -1333,7 +1333,7 @@ public override Task Where_datetime_hour_component(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (DateTimePart("hh", c["OrderDate"]) = 0)) +WHERE ((c["$type"] = "Order") AND (DateTimePart("hh", c["OrderDate"]) = 0)) """); }); @@ -1347,7 +1347,7 @@ public override Task Where_datetime_minute_component(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (DateTimePart("mi", c["OrderDate"]) = 0)) +WHERE ((c["$type"] = "Order") AND (DateTimePart("mi", c["OrderDate"]) = 0)) """); }); @@ -1361,7 +1361,7 @@ public override Task Where_datetime_second_component(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (DateTimePart("ss", c["OrderDate"]) = 0)) +WHERE ((c["$type"] = "Order") AND (DateTimePart("ss", c["OrderDate"]) = 0)) """); }); @@ -1375,7 +1375,7 @@ public override Task Where_datetime_millisecond_component(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (DateTimePart("ms", c["OrderDate"]) = 0)) +WHERE ((c["$type"] = "Order") AND (DateTimePart("ms", c["OrderDate"]) = 0)) """); }); @@ -1566,7 +1566,7 @@ public override Task Where_bool_member(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND c["Discontinued"]) +WHERE ((c["$type"] = "Product") AND c["Discontinued"]) """); }); @@ -1580,7 +1580,7 @@ public override Task Where_bool_member_false(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND NOT(c["Discontinued"])) +WHERE ((c["$type"] = "Product") AND NOT(c["Discontinued"])) """); }); @@ -1602,7 +1602,7 @@ public override Task Where_bool_member_negated_twice(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND NOT(NOT((c["Discontinued"] = true)))) +WHERE ((c["$type"] = "Product") AND NOT(NOT((c["Discontinued"] = true)))) """); }); @@ -1616,7 +1616,7 @@ public override Task Where_bool_member_shadow(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND c["Discontinued"]) +WHERE ((c["$type"] = "Product") AND c["Discontinued"]) """); }); @@ -1630,7 +1630,7 @@ public override Task Where_bool_member_false_shadow(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND NOT(c["Discontinued"])) +WHERE ((c["$type"] = "Product") AND NOT(c["Discontinued"])) """); }); @@ -1644,7 +1644,7 @@ public override Task Where_bool_member_equals_constant(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["Discontinued"] = true)) +WHERE ((c["$type"] = "Product") AND (c["Discontinued"] = true)) """); }); @@ -1658,7 +1658,7 @@ public override Task Where_bool_member_in_complex_predicate(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (((c["ProductID"] > 100) AND c["Discontinued"]) OR (c["Discontinued"] = true))) +WHERE ((c["$type"] = "Product") AND (((c["ProductID"] > 100) AND c["Discontinued"]) OR (c["Discontinued"] = true))) """); }); @@ -1672,7 +1672,7 @@ public override Task Where_bool_member_compared_to_binary_expression(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["Discontinued"] = (c["ProductID"] > 50))) +WHERE ((c["$type"] = "Product") AND (c["Discontinued"] = (c["ProductID"] > 50))) """); }); @@ -1686,7 +1686,7 @@ public override Task Where_not_bool_member_compared_to_not_bool_member(bool asyn """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (NOT(c["Discontinued"]) = NOT(c["Discontinued"]))) +WHERE ((c["$type"] = "Product") AND (NOT(c["Discontinued"]) = NOT(c["Discontinued"]))) """); }); @@ -1700,7 +1700,7 @@ public override Task Where_negated_boolean_expression_compared_to_another_negate """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (NOT((c["ProductID"] > 50)) = NOT((c["ProductID"] > 20)))) +WHERE ((c["$type"] = "Product") AND (NOT((c["ProductID"] > 50)) = NOT((c["ProductID"] > 20)))) """); }); @@ -1714,7 +1714,7 @@ public override Task Where_not_bool_member_compared_to_binary_expression(bool as """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (NOT(c["Discontinued"]) = (c["ProductID"] > 50))) +WHERE ((c["$type"] = "Product") AND (NOT(c["Discontinued"]) = (c["ProductID"] > 50))) """); }); @@ -1730,7 +1730,7 @@ public override Task Where_bool_parameter(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND @__prm_0) +WHERE ((c["$type"] = "Product") AND @__prm_0) """); }); @@ -1746,7 +1746,7 @@ public override Task Where_bool_parameter_compared_to_binary_expression(bool asy SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND ((c["ProductID"] > 50) != @__prm_0)) +WHERE ((c["$type"] = "Product") AND ((c["ProductID"] > 50) != @__prm_0)) """); }); @@ -1762,7 +1762,7 @@ public override Task Where_bool_member_and_parameter_compared_to_binary_expressi SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["Discontinued"] = ((c["ProductID"] > 50) != @__prm_0))) +WHERE ((c["$type"] = "Product") AND (c["Discontinued"] = ((c["ProductID"] > 50) != @__prm_0))) """); }); @@ -1776,7 +1776,7 @@ public override Task Where_de_morgan_or_optimized(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND NOT((c["Discontinued"] OR (c["ProductID"] < 20)))) +WHERE ((c["$type"] = "Product") AND NOT((c["Discontinued"] OR (c["ProductID"] < 20)))) """); }); @@ -1790,7 +1790,7 @@ public override Task Where_de_morgan_and_optimized(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND NOT((c["Discontinued"] AND (c["ProductID"] < 20)))) +WHERE ((c["$type"] = "Product") AND NOT((c["Discontinued"] AND (c["ProductID"] < 20)))) """); }); @@ -1804,7 +1804,7 @@ public override Task Where_complex_negated_expression_optimized(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND NOT((NOT((NOT(c["Discontinued"]) AND (c["ProductID"] < 60))) OR NOT((c["ProductID"] > 30))))) +WHERE ((c["$type"] = "Product") AND NOT((NOT((NOT(c["Discontinued"]) AND (c["ProductID"] < 60))) OR NOT((c["ProductID"] > 30))))) """); }); @@ -1818,7 +1818,7 @@ public override Task Where_short_member_comparison(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["UnitsInStock"] > 10)) +WHERE ((c["$type"] = "Product") AND (c["UnitsInStock"] > 10)) """); }); @@ -2017,7 +2017,7 @@ public override Task Where_ternary_boolean_condition_true(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["UnitsInStock"] >= 20)) +WHERE ((c["$type"] = "Product") AND (c["UnitsInStock"] >= 20)) """); }); @@ -2031,7 +2031,7 @@ public override Task Where_ternary_boolean_condition_false(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["UnitsInStock"] < 20)) +WHERE ((c["$type"] = "Product") AND (c["UnitsInStock"] < 20)) """); }); @@ -2047,7 +2047,7 @@ public override Task Where_ternary_boolean_condition_with_another_condition(bool SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND ((c["ProductID"] < @__productId_0) AND (c["UnitsInStock"] >= 20))) +WHERE ((c["$type"] = "Product") AND ((c["ProductID"] < @__productId_0) AND (c["UnitsInStock"] >= 20))) """); }); @@ -2061,7 +2061,7 @@ public override Task Where_ternary_boolean_condition_with_false_as_result_true(b """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (c["UnitsInStock"] >= 20)) +WHERE ((c["$type"] = "Product") AND (c["UnitsInStock"] >= 20)) """); }); @@ -2089,7 +2089,7 @@ public override Task Where_ternary_boolean_condition_negated(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND NOT(((c["UnitsInStock"] >= 20) ? false : true))) +WHERE ((c["$type"] = "Product") AND NOT(((c["UnitsInStock"] >= 20) ? false : true))) """); }); @@ -2202,7 +2202,7 @@ public override Task Where_chain(bool async) """ SELECT VALUE c FROM root c -WHERE (((c["Discriminator"] = "Order") AND (c["CustomerID"] = "QUICK")) AND (c["OrderDate"] > "1998-01-01T00:00:00")) +WHERE (((c["$type"] = "Order") AND (c["CustomerID"] = "QUICK")) AND (c["OrderDate"] > "1998-01-01T00:00:00")) """); }); @@ -2279,7 +2279,7 @@ public override Task Time_of_day_datetime(bool async) """ SELECT VALUE c["OrderDate"] FROM root c -WHERE (c["Discriminator"] = "Order") +WHERE (c["$type"] = "Order") """); }); @@ -2295,7 +2295,7 @@ public override Task TypeBinary_short_circuit(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND @__p_0) +WHERE ((c["$type"] = "Order") AND @__p_0) """); }); @@ -2317,7 +2317,7 @@ public override Task Where_is_conditional(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Product") AND (true ? false : true)) +WHERE ((c["$type"] = "Product") AND (true ? false : true)) """); }); @@ -2501,7 +2501,7 @@ public override Task Where_list_object_contains_over_value_type(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ARRAY_CONTAINS(@__orderIds_0, c["OrderID"])) +WHERE ((c["$type"] = "Order") AND ARRAY_CONTAINS(@__orderIds_0, c["OrderID"])) """); }); @@ -2517,7 +2517,7 @@ public override Task Where_array_of_object_contains_over_value_type(bool async) SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND ARRAY_CONTAINS(@__orderIds_0, c["OrderID"])) +WHERE ((c["$type"] = "Order") AND ARRAY_CONTAINS(@__orderIds_0, c["OrderID"])) """); }); @@ -3246,7 +3246,7 @@ public override Task Implicit_cast_in_predicate(bool async) """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "1337")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "1337")) """, // """ @@ -3254,7 +3254,7 @@ FROM root c SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = @__prm_Value_0)) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = @__prm_Value_0)) """, // """ @@ -3262,7 +3262,7 @@ FROM root c SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = @__ToString_0)) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = @__ToString_0)) """, // """ @@ -3270,13 +3270,13 @@ FROM root c SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = @__p_0)) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = @__p_0)) """, // """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["CustomerID"] = "1337")) +WHERE ((c["$type"] = "Order") AND (c["CustomerID"] = "1337")) """); }); @@ -3292,25 +3292,25 @@ public override Task Interface_casting_though_generic_method(bool async) SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = @__id_0)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = @__id_0)) """, // """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 10252)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 10252)) """, // """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 10252)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 10252)) """, // """ SELECT VALUE c["OrderID"] FROM root c -WHERE ((c["Discriminator"] = "Order") AND (c["OrderID"] = 10252)) +WHERE ((c["$type"] = "Order") AND (c["OrderID"] = 10252)) """); }); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs index c94ce08760d..169931115d1 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs @@ -57,7 +57,7 @@ public override Task Navigation_rewrite_on_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(c["Orders"]) > 0)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(c["Orders"]) > 0)) ORDER BY c["Id"] """); }); @@ -79,7 +79,7 @@ SELECT VALUE (o["Id"] != 42) FROM o IN c["Orders"] ORDER BY o["Id"])[0] ?? false) FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Id"] """); } @@ -108,7 +108,7 @@ public override Task Navigation_rewrite_on_owned_reference_projecting_entity(boo """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["Country"]["Name"] = "USA")) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["Country"]["Name"] = "USA")) """); }); @@ -122,7 +122,7 @@ public override Task Navigation_rewrite_on_owned_reference_projecting_scalar(boo """ SELECT VALUE c["PersonAddress"]["Country"]["Name"] FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["Country"]["Name"] = "USA")) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["Country"]["Name"] = "USA")) """); }); @@ -136,7 +136,7 @@ public override Task Query_for_base_type_loads_all_owned_navs(bool async) """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -150,7 +150,7 @@ public override Task Query_for_branch_type_loads_all_owned_navs(bool async) """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("Branch", "LeafA") +WHERE c["Terminator"] IN ("Branch", "LeafA") """); }); @@ -164,7 +164,7 @@ public override Task Query_for_branch_type_loads_all_owned_navs_tracking(bool as """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("Branch", "LeafA") +WHERE c["Terminator"] IN ("Branch", "LeafA") """); }); @@ -178,7 +178,7 @@ public override Task Query_for_leaf_type_loads_all_owned_navs(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "LeafA") +WHERE (c["Terminator"] = "LeafA") """); }); @@ -313,7 +313,7 @@ public override Task SelectMany_on_owned_collection(bool async) SELECT VALUE o FROM root c JOIN o IN c["Orders"] -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -334,7 +334,7 @@ SELECT VALUE } FROM root c JOIN o IN c["Orders"] -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -367,7 +367,7 @@ public override Task Query_with_OfType_eagerly_loads_correct_owned_navigations(b """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Discriminator"] = "LeafA")) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Terminator"] = "LeafA")) """); }); @@ -386,7 +386,7 @@ public override Task Project_owned_reference_navigation_which_owns_additional(bo """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Id"] """); }); @@ -417,7 +417,7 @@ public override Task No_ignored_include_warning_when_implicit_load(bool async) """ SELECT VALUE COUNT(1) FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -458,7 +458,7 @@ await AssertQuery( SELECT VALUE o["Details"] FROM root c JOIN o IN c["Orders"] -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) ORDER BY c["Id"] """); }); @@ -485,7 +485,7 @@ await AssertQuery( SELECT VALUE o FROM root c JOIN o IN c["Orders"] -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) ORDER BY c["Id"] """); }); @@ -512,7 +512,7 @@ await AssertQuery( SELECT VALUE o FROM root c JOIN o IN c["Orders"] -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) ORDER BY c["Id"] """); }); @@ -539,7 +539,7 @@ await AssertQuery( SELECT VALUE o["Details"] FROM root c JOIN o IN c["Orders"] -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) ORDER BY c["Id"] """); }); @@ -566,7 +566,7 @@ await AssertQuery( SELECT VALUE o FROM root c JOIN o IN c["Orders"] -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(o["Details"]) = 1)) ORDER BY c["Id"] """); }); @@ -585,7 +585,7 @@ public override Task Can_query_on_indexer_properties(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Name"] = "Mona Cy")) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Name"] = "Mona Cy")) """); }); @@ -599,7 +599,7 @@ public override Task Can_query_on_owned_indexer_properties(bool async) """ SELECT VALUE c["Name"] FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["ZipCode"] = 38654)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["ZipCode"] = 38654)) """); }); @@ -613,7 +613,7 @@ public override Task Can_query_on_indexer_property_when_property_name_from_closu """ SELECT VALUE c["Name"] FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Name"] = "Mona Cy")) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Name"] = "Mona Cy")) """); }); @@ -627,7 +627,7 @@ public override Task Can_project_indexer_properties(bool async) """ SELECT VALUE c["Name"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -641,7 +641,7 @@ public override Task Can_project_owned_indexer_properties(bool async) """ SELECT VALUE c["PersonAddress"]["AddressLine"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -655,7 +655,7 @@ public override Task Can_project_indexer_properties_converted(bool async) """ SELECT VALUE c["Name"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -674,7 +674,7 @@ public override async Task Can_OrderBy_indexer_properties(bool async) """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Name"], c["Id"] """); } @@ -695,7 +695,7 @@ public override async Task Can_OrderBy_indexer_properties_converted(bool async) """ SELECT VALUE c["Name"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Name"], c["Id"] """); } @@ -716,7 +716,7 @@ public override async Task Can_OrderBy_owned_indexer_properties(bool async) """ SELECT VALUE c["Name"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["PersonAddress"]["ZipCode"], c["Id"] """); } @@ -737,7 +737,7 @@ public override async Task Can_OrderBy_owned_indexer_properties_converted(bool a """ SELECT VALUE c["Name"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["PersonAddress"]["ZipCode"], c["Id"] """); } @@ -773,7 +773,7 @@ public override Task Projecting_indexer_property_ignores_include(bool async) """ SELECT VALUE c["PersonAddress"]["ZipCode"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -787,7 +787,7 @@ public override Task Projecting_indexer_property_ignores_include_converted(bool """ SELECT VALUE c["PersonAddress"]["ZipCode"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -806,7 +806,7 @@ public override Task Can_query_indexer_property_on_owned_collection(bool async) """ SELECT VALUE c["Name"] FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (( +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (( SELECT VALUE COUNT(1) FROM o IN c["Orders"] WHERE (DateTimePart("yyyy", o["OrderDate"]) = 2018)) = 1)) @@ -850,7 +850,7 @@ public override async Task Ordering_by_identifying_projection(bool async) """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["PersonAddress"]["PlaceType"], c["Id"] """); } @@ -871,7 +871,7 @@ public override Task Query_on_collection_entry_works_for_owned_collection(bool a SELECT VALUE o FROM root c JOIN o IN c["Orders"] -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (o["ClientId"] = @__p_0)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (o["ClientId"] = @__p_0)) """); }); @@ -917,7 +917,7 @@ public override Task Filter_on_indexer_using_closure(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["ZipCode"] = 38654)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["ZipCode"] = 38654)) """); }); @@ -931,7 +931,7 @@ public override Task Filter_on_indexer_using_function_argument(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["ZipCode"] = 38654)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["PersonAddress"]["ZipCode"] = 38654)) """); }); @@ -949,7 +949,7 @@ public override Task Can_project_owned_indexer_properties_converted(bool async) """ SELECT VALUE c["PersonAddress"]["AddressLine"] FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -963,7 +963,7 @@ public override Task Can_query_owner_with_different_owned_types_having_same_prop """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("HeliumBalloon", "HydrogenBalloon") +WHERE c["Terminator"] IN ("HeliumBalloon", "HydrogenBalloon") """); }); @@ -980,7 +980,7 @@ public override Task Client_method_skip_take_loads_owned_navigations_variation_2 SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Id"] OFFSET @__p_0 LIMIT @__p_1 """); @@ -999,7 +999,7 @@ public override Task Client_method_skip_take_loads_owned_navigations(bool async) SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Id"] OFFSET @__p_0 LIMIT @__p_1 """); @@ -1022,7 +1022,7 @@ await Assert.ThrowsAsync( """ SELECT VALUE c["Throned"]["Value"] FROM root c -WHERE (c["Discriminator"] = "Barton") +WHERE (c["Terminator"] = "Barton") """); }); } @@ -1038,7 +1038,7 @@ public override Task Owned_entity_without_owner_does_not_throw_for_identity_reso """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -1052,7 +1052,7 @@ public override Task Simple_query_entity_with_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "Star") +WHERE (c["Terminator"] = "Star") """); }); @@ -1066,7 +1066,7 @@ public override Task Throw_for_owned_entities_without_owner_in_tracking_query(bo """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") """); }); @@ -1080,7 +1080,7 @@ public override Task Unmapped_property_projection_loads_owned_navigations(bool a """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Id"] = 1)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Id"] = 1)) """); }); @@ -1096,7 +1096,7 @@ public override Task Client_method_take_loads_owned_navigations(bool async) SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Id"] OFFSET 0 LIMIT @__p_0 """); @@ -1116,7 +1116,7 @@ public override Task Client_method_take_loads_owned_navigations_variation_2(bool SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Id"] OFFSET 0 LIMIT @__p_0 """); @@ -1134,7 +1134,7 @@ public override Task Count_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(c["Orders"]) = 2)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(c["Orders"]) = 2)) """); }); @@ -1150,7 +1150,7 @@ public override Task Any_without_predicate_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(c["Orders"]) > 0)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(c["Orders"]) > 0)) """); }); @@ -1166,7 +1166,7 @@ public override Task Any_with_predicate_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND EXISTS ( +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND EXISTS ( SELECT 1 FROM o IN c["Orders"] WHERE (o["Id"] = -30))) @@ -1185,7 +1185,7 @@ public override Task Contains_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND EXISTS ( +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND EXISTS ( SELECT 1 FROM o IN c["Orders"] WHERE (o["Id"] = -30))) @@ -1204,7 +1204,7 @@ public override Task ElementAt_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Orders"][1]["Id"] = -11)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (c["Orders"][1]["Id"] = -11)) """); }); @@ -1220,7 +1220,7 @@ public override Task ElementAtOrDefault_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND ((c["Orders"][10] ?? null)["Id"] = -11)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND ((c["Orders"][10] ?? null)["Id"] = -11)) """); }); @@ -1239,7 +1239,7 @@ public override async Task OrderBy_ElementAt_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY( +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY( SELECT VALUE o["Id"] FROM o IN c["Orders"] ORDER BY o["Id"])[1] = -10)) @@ -1259,7 +1259,7 @@ public override Task Skip_Take_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(ARRAY_SLICE(c["Orders"], 1, 1)) = 1)) +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(ARRAY_SLICE(c["Orders"], 1, 1)) = 1)) """); }); @@ -1275,7 +1275,7 @@ public override Task FirstOrDefault_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (DateTimePart("yyyy", (ARRAY( +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (DateTimePart("yyyy", (ARRAY( SELECT VALUE o["OrderDate"] FROM o IN c["Orders"] WHERE (o["Id"] > -20))[0] ?? "0001-01-01T00:00:00")) = 2018)) @@ -1308,7 +1308,7 @@ public override Task Union_over_owned_collection(bool async) """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(SetUnion(ARRAY( +WHERE (c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") AND (ARRAY_LENGTH(SetUnion(ARRAY( SELECT VALUE o FROM o IN c["Orders"] WHERE (o["Id"] = -10)), ARRAY( @@ -1723,6 +1723,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder .Entity() .OwnsOne(e => e.Gas); + + modelBuilder.HasEmbeddedDiscriminatorName("Terminator"); } } } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs index e008810bb84..5a1d15393f2 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs @@ -1793,7 +1793,7 @@ public override Task Project_collection_of_nullable_ints_with_distinct(bool asyn """ SELECT VALUE {"c" : [c["String"], "foo"]} FROM root c -WHERE (c["Discriminator"] = "PrimitiveCollectionsEntity") +WHERE (c["$type"] = "PrimitiveCollectionsEntity") """); }); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryDiscriminatorInIdTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryDiscriminatorInIdTest.cs index ff64e65252e..77d0b9e5752 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryDiscriminatorInIdTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryDiscriminatorInIdTest.cs @@ -26,7 +26,7 @@ public override async Task Predicate_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") """); } @@ -39,7 +39,7 @@ public override async Task Predicate_with_only_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") """); } @@ -52,7 +52,7 @@ public override async Task Predicate_with_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") +WHERE c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") """); } @@ -65,7 +65,7 @@ public override async Task Predicate_with_only_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") +WHERE c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") """); } @@ -78,7 +78,7 @@ public override async Task Predicate_with_partial_values_in_hierarchical_partiti """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) +WHERE (c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) """); } @@ -91,7 +91,7 @@ public override async Task Predicate_with_partial_values_in_only_hierarchical_pa """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1a") AND (c["PartitionKey2"] = 1))) +WHERE (c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1a") AND (c["PartitionKey2"] = 1))) """); } @@ -105,7 +105,7 @@ public override async Task Predicate_with_hierarchical_partition_key_and_additio """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE (c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -119,7 +119,7 @@ public override async Task Predicate_with_only_hierarchical_partition_key_and_ad """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE (c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -132,7 +132,7 @@ public override async Task WithPartitionKey_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") """); } @@ -145,7 +145,7 @@ public override async Task WithPartitionKey_with_only_hierarchical_partition_key """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") """); } @@ -158,7 +158,7 @@ public override async Task WithPartitionKey_with_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") +WHERE c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") """); } @@ -171,7 +171,7 @@ public override async Task WithPartitionKey_with_only_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") +WHERE c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") """); } @@ -191,7 +191,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) """); } @@ -204,7 +204,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2a")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2a")) """); } @@ -217,7 +217,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) """); } @@ -230,7 +230,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1a")) +WHERE (c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1a")) """); } @@ -243,7 +243,7 @@ public override async Task ReadItem_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -256,7 +256,7 @@ public override async Task ReadItem_with_only_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") """); } @@ -268,7 +268,7 @@ public override async Task ReadItem_with_single_partition_key_constant() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -281,7 +281,7 @@ public override async Task ReadItem_with_only_single_partition_key_constant() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") +WHERE c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") """); } @@ -294,7 +294,7 @@ public override async Task ReadItem_with_single_partition_key_parameter() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -307,7 +307,7 @@ public override async Task ReadItem_with_only_single_partition_key_parameter() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") +WHERE c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") """); } @@ -316,10 +316,11 @@ public override async Task ReadItem_with_SingleAsync() await base.ReadItem_with_SingleAsync(); // Not ReadItem because discriminator value in the JSON id is unknown - AssertSql(""" + AssertSql( + """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) OFFSET 0 LIMIT 2 """); } @@ -329,10 +330,11 @@ public override async Task ReadItem_with_SingleAsync_with_only_partition_key() await base.ReadItem_with_SingleAsync_with_only_partition_key(); // Not ReadItem because discriminator value in the JSON id is unknown - AssertSql(""" + AssertSql( + """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") +WHERE c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") OFFSET 0 LIMIT 2 """); } @@ -345,7 +347,7 @@ public override async Task ReadItem_with_inverse_comparison() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (1 = c["Id"])) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (1 = c["Id"])) """); } @@ -358,7 +360,7 @@ public override async Task ReadItem_with_inverse_comparison_with_only_partition_ """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") +WHERE c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") """); } @@ -371,7 +373,7 @@ public override async Task ReadItem_with_EF_Property() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -384,7 +386,7 @@ public override async Task ReadItem_with_WithPartitionKey() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -395,7 +397,7 @@ public override async Task ReadItem_with_WithPartitionKey_with_only_partition_ke """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1a")) +WHERE (c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1a")) """); } @@ -408,7 +410,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Id"] = 2))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Id"] = 2))) """); } @@ -424,7 +426,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND ((c["PartitionKey"] = "PK1a") AND (c["PartitionKey"] = @__partitionKey_0))) +WHERE (c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND ((c["PartitionKey"] = "PK1a") AND (c["PartitionKey"] = @__partitionKey_0))) """); } @@ -437,7 +439,7 @@ public override async Task ReadItem_with_no_partition_key() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("NoPartitionKeyEntity", "DerivedNoPartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("NoPartitionKeyEntity", "DerivedNoPartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -449,7 +451,7 @@ public override async Task ReadItem_is_not_used_without_partition_key() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -460,7 +462,7 @@ public override async Task ReadItem_with_non_existent_id() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 999)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 999)) """); } @@ -472,7 +474,7 @@ public override async Task ReadItem_with_AsNoTracking() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -485,7 +487,7 @@ public override async Task ReadItem_with_AsNoTrackingWithIdentityResolution() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -506,7 +508,7 @@ public override async Task ReadItem_for_base_type_with_shared_container() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SharedContainerEntity2", "SharedContainerEntity2Child") AND (c["Id"] = 4)) +WHERE (c["$type"] IN ("SharedContainerEntity2", "SharedContainerEntity2Child") AND (c["Id"] = 4)) """); } @@ -528,7 +530,7 @@ public override async Task Predicate_with_hierarchical_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedHierarchicalPartitionKeyEntity") """); } @@ -548,7 +550,7 @@ public override async Task Predicate_with_single_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedSinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedSinglePartitionKeyEntity") """); } @@ -568,7 +570,7 @@ public override async Task Predicate_with_partial_values_in_hierarchical_partiti """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) +WHERE ((c["$type"] = "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) """); } @@ -581,7 +583,7 @@ public override async Task Predicate_with_partial_values_in_only_hierarchical_pa """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1c") AND (c["PartitionKey2"] = 1))) +WHERE ((c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1c") AND (c["PartitionKey2"] = 1))) """); } @@ -595,7 +597,7 @@ public override async Task Predicate_with_hierarchical_partition_key_and_additio """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE ((c["$type"] = "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -609,7 +611,7 @@ public override async Task Predicate_with_only_hierarchical_partition_key_and_ad """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE ((c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -622,7 +624,7 @@ public override async Task WithPartitionKey_with_hierarchical_partition_key_leaf """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedHierarchicalPartitionKeyEntity") """); } @@ -635,7 +637,7 @@ public override async Task WithPartitionKey_with_only_hierarchical_partition_key """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") """); } @@ -648,7 +650,7 @@ public override async Task WithPartitionKey_with_single_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedSinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedSinglePartitionKeyEntity") """); } @@ -661,7 +663,7 @@ public override async Task WithPartitionKey_with_only_single_partition_key_leaf( """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedOnlySinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedOnlySinglePartitionKeyEntity") """); } @@ -681,7 +683,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) """); } @@ -694,7 +696,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2c")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2c")) """); } @@ -707,7 +709,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) """); } @@ -818,7 +820,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Id"] = 22))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Id"] = 22))) """); } @@ -833,7 +835,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlySinglePartitionKeyEntity") AND ((c["PartitionKey"] = "PK1c") AND (c["PartitionKey"] = @__partitionKey_0))) +WHERE ((c["$type"] = "DerivedOnlySinglePartitionKeyEntity") AND ((c["PartitionKey"] = "PK1c") AND (c["PartitionKey"] = @__partitionKey_0))) """); } @@ -852,7 +854,7 @@ public override async Task ReadItem_is_not_used_without_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 11)) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 11)) """); } @@ -886,7 +888,7 @@ public override async Task ReadItem_with_single_explicit_discriminator_mapping() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Discriminator"] = "SinglePartitionKeyEntity"))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["$type"] = "SinglePartitionKeyEntity"))) OFFSET 0 LIMIT 2 """); } @@ -900,7 +902,7 @@ public override async Task ReadItem_with_single_explicit_incorrect_discriminator """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Discriminator"] = "DerivedSinglePartitionKeyEntity"))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["$type"] = "DerivedSinglePartitionKeyEntity"))) """); } @@ -915,7 +917,7 @@ public override async Task ReadItem_with_single_explicit_parameterized_discrimin SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Discriminator"] = @__discriminator_0))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["$type"] = @__discriminator_0))) OFFSET 0 LIMIT 2 """); } @@ -936,7 +938,7 @@ public override async Task ReadItem_with_single_explicit_incorrect_discriminator """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Discriminator"] = "SinglePartitionKeyEntity"))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["$type"] = "SinglePartitionKeyEntity"))) """); } @@ -951,7 +953,7 @@ public override async Task ReadItem_with_single_explicit_parameterized_discrimin SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Discriminator"] = @__discriminator_0))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["$type"] = @__discriminator_0))) OFFSET 0 LIMIT 2 """); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryInheritanceTestBase.cs b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryInheritanceTestBase.cs index 8a55a499f8c..a3192ebd864 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryInheritanceTestBase.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryInheritanceTestBase.cs @@ -325,7 +325,7 @@ public virtual Task ReadItem_with_single_explicit_discriminator_mapping_leaf() ss => ss.Set() .Where( e => e.Id == 11 - && EF.Property(e, "Discriminator") == nameof(DerivedSinglePartitionKeyEntity) + && EF.Property(e, "$type") == nameof(DerivedSinglePartitionKeyEntity) && e.PartitionKey == partitionKey), ss => ss.Set() .Where(e => e.Id == 11 && e.PartitionKey == partitionKey)); @@ -341,7 +341,7 @@ public virtual Task ReadItem_with_single_explicit_incorrect_discriminator_mappin ss => ss.Set() .Where( e => e.Id == 11 - && EF.Property(e, "Discriminator") == nameof(SinglePartitionKeyEntity) + && EF.Property(e, "$type") == nameof(SinglePartitionKeyEntity) && e.PartitionKey == partitionKey), ss => ss.Set().Where(e => false), assertEmpty: true); @@ -356,7 +356,7 @@ public virtual Task ReadItem_with_single_explicit_parameterized_discriminator_ma return AssertSingle( async: true, ss => ss.Set() - .Where(e => e.Id == 11 && EF.Property(e, "Discriminator") == discriminator && e.PartitionKey == partitionKey), + .Where(e => e.Id == 11 && EF.Property(e, "$type") == discriminator && e.PartitionKey == partitionKey), ss => ss.Set().Where(e => e.Id == 11 && e.PartitionKey == partitionKey)); } } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryNoDiscriminatorInIdTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryNoDiscriminatorInIdTest.cs index 49cfa0df4a6..3257a0cb567 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryNoDiscriminatorInIdTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryNoDiscriminatorInIdTest.cs @@ -26,7 +26,7 @@ public override async Task Predicate_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") """); } @@ -46,7 +46,7 @@ public override async Task Predicate_with_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") +WHERE c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") """); } @@ -63,10 +63,10 @@ public override async Task Predicate_with_partial_values_in_hierarchical_partiti // Not ReadItem because no primary key value AssertSql( - """ + """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) +WHERE (c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) """); } @@ -79,7 +79,7 @@ public override async Task Predicate_with_partial_values_in_only_hierarchical_pa """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1a") AND (c["PartitionKey2"] = 1))) +WHERE (c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1a") AND (c["PartitionKey2"] = 1))) """); } @@ -92,7 +92,7 @@ public override async Task Predicate_with_hierarchical_partition_key_and_additio """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE (c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -105,7 +105,7 @@ public override async Task Predicate_with_only_hierarchical_partition_key_and_ad """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE (c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -118,7 +118,7 @@ public override async Task WithPartitionKey_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") """); } @@ -131,7 +131,7 @@ public override async Task WithPartitionKey_with_only_hierarchical_partition_key """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") """); } @@ -144,7 +144,7 @@ public override async Task WithPartitionKey_with_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") +WHERE c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") """); } @@ -157,7 +157,7 @@ public override async Task WithPartitionKey_with_only_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") +WHERE c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") """); } @@ -177,7 +177,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) """); } @@ -190,7 +190,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2a")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2a")) """); } @@ -203,7 +203,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) """); } @@ -314,7 +314,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Id"] = 2))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Id"] = 2))) """); } @@ -329,7 +329,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND ((c["id"] = "PK1a") AND (c["id"] = @__partitionKey_0))) +WHERE (c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND ((c["id"] = "PK1a") AND (c["id"] = @__partitionKey_0))) """); } @@ -348,7 +348,7 @@ public override async Task ReadItem_is_not_used_without_partition_key() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -404,7 +404,7 @@ public override async Task Predicate_with_hierarchical_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedHierarchicalPartitionKeyEntity") """); } @@ -424,7 +424,7 @@ public override async Task Predicate_with_single_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedSinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedSinglePartitionKeyEntity") """); } @@ -444,7 +444,7 @@ public override async Task Predicate_with_partial_values_in_hierarchical_partiti """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) +WHERE ((c["$type"] = "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) """); } @@ -457,7 +457,7 @@ public override async Task Predicate_with_partial_values_in_only_hierarchical_pa """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1c") AND (c["PartitionKey2"] = 1))) +WHERE ((c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1c") AND (c["PartitionKey2"] = 1))) """); } @@ -470,7 +470,7 @@ public override async Task Predicate_with_hierarchical_partition_key_and_additio """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE ((c["$type"] = "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -483,7 +483,7 @@ public override async Task Predicate_with_only_hierarchical_partition_key_and_ad """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE ((c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -496,7 +496,7 @@ public override async Task WithPartitionKey_with_hierarchical_partition_key_leaf """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedHierarchicalPartitionKeyEntity") """); } @@ -509,7 +509,7 @@ public override async Task WithPartitionKey_with_only_hierarchical_partition_key """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") """); } @@ -522,7 +522,7 @@ public override async Task WithPartitionKey_with_single_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedSinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedSinglePartitionKeyEntity") """); } @@ -535,7 +535,7 @@ public override async Task WithPartitionKey_with_only_single_partition_key_leaf( """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedOnlySinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedOnlySinglePartitionKeyEntity") """); } @@ -555,7 +555,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) """); } @@ -568,7 +568,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2c")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2c")) """); } @@ -581,7 +581,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) """); } @@ -692,7 +692,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Id"] = 22))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Id"] = 22))) """); } @@ -707,7 +707,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlySinglePartitionKeyEntity") AND ((c["id"] = "PK1c") AND (c["id"] = @__partitionKey_0))) +WHERE ((c["$type"] = "DerivedOnlySinglePartitionKeyEntity") AND ((c["id"] = "PK1c") AND (c["id"] = @__partitionKey_0))) """); } @@ -726,7 +726,7 @@ public override async Task ReadItem_is_not_used_without_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 11)) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 11)) """); } @@ -766,7 +766,7 @@ public override async Task ReadItem_with_single_explicit_incorrect_discriminator """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Discriminator"] = "DerivedSinglePartitionKeyEntity"))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["$type"] = "DerivedSinglePartitionKeyEntity"))) """); } @@ -781,7 +781,7 @@ public override async Task ReadItem_with_single_explicit_parameterized_discrimin SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Discriminator"] = @__discriminator_0))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["$type"] = @__discriminator_0))) OFFSET 0 LIMIT 2 """); } @@ -802,7 +802,7 @@ public override async Task ReadItem_with_single_explicit_incorrect_discriminator """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Discriminator"] = "SinglePartitionKeyEntity"))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["$type"] = "SinglePartitionKeyEntity"))) """); } @@ -817,7 +817,7 @@ public override async Task ReadItem_with_single_explicit_parameterized_discrimin SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Discriminator"] = @__discriminator_0))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["$type"] = @__discriminator_0))) OFFSET 0 LIMIT 2 """); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryRootDiscriminatorInIdTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryRootDiscriminatorInIdTest.cs index 4f12b9b888c..ef9ddfb5cde 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryRootDiscriminatorInIdTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryRootDiscriminatorInIdTest.cs @@ -26,7 +26,7 @@ public override async Task Predicate_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") """); } @@ -46,7 +46,7 @@ public override async Task Predicate_with_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") +WHERE c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") """); } @@ -66,7 +66,7 @@ public override async Task Predicate_with_partial_values_in_hierarchical_partiti """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) +WHERE (c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) """); } @@ -79,7 +79,7 @@ public override async Task Predicate_with_partial_values_in_only_hierarchical_pa """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1a") AND (c["PartitionKey2"] = 1))) +WHERE (c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1a") AND (c["PartitionKey2"] = 1))) """); } @@ -93,7 +93,7 @@ public override async Task Predicate_with_hierarchical_partition_key_and_additio """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE (c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -107,7 +107,7 @@ public override async Task Predicate_with_only_hierarchical_partition_key_and_ad """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE (c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -120,7 +120,7 @@ public override async Task WithPartitionKey_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("HierarchicalPartitionKeyEntity", "DerivedHierarchicalPartitionKeyEntity") """); } @@ -133,7 +133,7 @@ public override async Task WithPartitionKey_with_only_hierarchical_partition_key """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") +WHERE c["$type"] IN ("OnlyHierarchicalPartitionKeyEntity", "DerivedOnlyHierarchicalPartitionKeyEntity") """); } @@ -146,7 +146,7 @@ public override async Task WithPartitionKey_with_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") +WHERE c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") """); } @@ -159,7 +159,7 @@ public override async Task WithPartitionKey_with_only_single_partition_key() """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") +WHERE c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") """); } @@ -179,7 +179,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) """); } @@ -192,7 +192,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2a")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2a")) """); } @@ -205,7 +205,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) """); } @@ -316,7 +316,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Id"] = 2))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Id"] = 2))) """); } @@ -332,7 +332,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND ((c["PartitionKey"] = "PK1a") AND (c["PartitionKey"] = @__partitionKey_0))) +WHERE (c["$type"] IN ("OnlySinglePartitionKeyEntity", "DerivedOnlySinglePartitionKeyEntity") AND ((c["PartitionKey"] = "PK1a") AND (c["PartitionKey"] = @__partitionKey_0))) """); } @@ -351,7 +351,7 @@ public override async Task ReadItem_is_not_used_without_partition_key() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 1)) """); } @@ -406,7 +406,7 @@ public override async Task Predicate_with_hierarchical_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedHierarchicalPartitionKeyEntity") """); } @@ -426,7 +426,7 @@ public override async Task Predicate_with_single_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedSinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedSinglePartitionKeyEntity") """); } @@ -446,7 +446,7 @@ public override async Task Predicate_with_partial_values_in_hierarchical_partiti """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) +WHERE ((c["$type"] = "DerivedHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) """); } @@ -459,7 +459,7 @@ public override async Task Predicate_with_partial_values_in_only_hierarchical_pa """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1c") AND (c["PartitionKey2"] = 1))) +WHERE ((c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1c") AND (c["PartitionKey2"] = 1))) """); } @@ -473,7 +473,7 @@ public override async Task Predicate_with_hierarchical_partition_key_and_additio """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE ((c["$type"] = "DerivedHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -487,7 +487,7 @@ public override async Task Predicate_with_only_hierarchical_partition_key_and_ad """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE ((c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -500,7 +500,7 @@ public override async Task WithPartitionKey_with_hierarchical_partition_key_leaf """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedHierarchicalPartitionKeyEntity") """); } @@ -513,7 +513,7 @@ public override async Task WithPartitionKey_with_only_hierarchical_partition_key """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedOnlyHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "DerivedOnlyHierarchicalPartitionKeyEntity") """); } @@ -526,7 +526,7 @@ public override async Task WithPartitionKey_with_single_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedSinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedSinglePartitionKeyEntity") """); } @@ -539,7 +539,7 @@ public override async Task WithPartitionKey_with_only_single_partition_key_leaf( """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "DerivedOnlySinglePartitionKeyEntity") +WHERE (c["$type"] = "DerivedOnlySinglePartitionKeyEntity") """); } @@ -559,7 +559,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2")) """); } @@ -572,7 +572,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2c")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK2c")) """); } @@ -585,7 +585,7 @@ public override async Task Both_WithPartitionKey_and_predicate_comparisons_with_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["PartitionKey"] = "PK1")) """); } @@ -696,7 +696,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Id"] = 22))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Id"] = 22))) """); } @@ -711,7 +711,7 @@ public override async Task Multiple_incompatible_predicate_comparisons_cause_no_ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedOnlySinglePartitionKeyEntity") AND ((c["PartitionKey"] = "PK1c") AND (c["PartitionKey"] = @__partitionKey_0))) +WHERE ((c["$type"] = "DerivedOnlySinglePartitionKeyEntity") AND ((c["PartitionKey"] = "PK1c") AND (c["PartitionKey"] = @__partitionKey_0))) """); } @@ -730,7 +730,7 @@ public override async Task ReadItem_is_not_used_without_partition_key_leaf() """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 11)) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND (c["Id"] = 11)) """); } @@ -771,7 +771,7 @@ public override async Task ReadItem_with_single_explicit_incorrect_discriminator """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Discriminator"] = "DerivedSinglePartitionKeyEntity"))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["$type"] = "DerivedSinglePartitionKeyEntity"))) """); } @@ -786,7 +786,7 @@ public override async Task ReadItem_with_single_explicit_parameterized_discrimin SELECT VALUE c FROM root c -WHERE (c["Discriminator"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["Discriminator"] = @__discriminator_0))) +WHERE (c["$type"] IN ("SinglePartitionKeyEntity", "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 1) AND (c["$type"] = @__discriminator_0))) OFFSET 0 LIMIT 2 """); } @@ -807,7 +807,7 @@ public override async Task ReadItem_with_single_explicit_incorrect_discriminator """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Discriminator"] = "SinglePartitionKeyEntity"))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["$type"] = "SinglePartitionKeyEntity"))) """); } @@ -822,7 +822,7 @@ public override async Task ReadItem_with_single_explicit_parameterized_discrimin SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["Discriminator"] = @__discriminator_0))) +WHERE ((c["$type"] = "DerivedSinglePartitionKeyEntity") AND ((c["Id"] = 11) AND (c["$type"] = @__discriminator_0))) OFFSET 0 LIMIT 2 """); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryTest.cs index 89726470724..8abdbf7796f 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryTest.cs @@ -25,7 +25,7 @@ public override async Task Predicate_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "HierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "HierarchicalPartitionKeyEntity") """); } @@ -64,7 +64,7 @@ public override async Task Predicate_with_partial_values_in_hierarchical_partiti """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "HierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) +WHERE ((c["$type"] = "HierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1") AND (c["PartitionKey2"] = 1))) """); } @@ -78,7 +78,7 @@ public override async Task Predicate_with_partial_values_in_only_hierarchical_pa """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "OnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1a") AND (c["PartitionKey2"] = 1))) +WHERE ((c["$type"] = "OnlyHierarchicalPartitionKeyEntity") AND ((c["PartitionKey1"] = "PK1a") AND (c["PartitionKey2"] = 1))) """); } @@ -91,7 +91,7 @@ public override async Task Predicate_with_hierarchical_partition_key_and_additio """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "HierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE ((c["$type"] = "HierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -104,7 +104,7 @@ public override async Task Predicate_with_only_hierarchical_partition_key_and_ad """ SELECT VALUE c FROM root c -WHERE ((c["Discriminator"] = "OnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) +WHERE ((c["$type"] = "OnlyHierarchicalPartitionKeyEntity") AND CONTAINS(c["Payload"], "3")) """); } @@ -117,7 +117,7 @@ public override async Task WithPartitionKey_with_hierarchical_partition_key() """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "HierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "HierarchicalPartitionKeyEntity") """); } @@ -130,7 +130,7 @@ public override async Task WithPartitionKey_with_only_hierarchical_partition_key """ SELECT VALUE c FROM root c -WHERE (c["Discriminator"] = "OnlyHierarchicalPartitionKeyEntity") +WHERE (c["$type"] = "OnlyHierarchicalPartitionKeyEntity") """); } @@ -409,7 +409,7 @@ public override async Task ReadItem_with_single_explicit_incorrect_discriminator """ SELECT VALUE c FROM root c -WHERE ((c["Id"] = 1) AND (c["Discriminator"] = "DerivedSinglePartitionKeyEntity")) +WHERE ((c["Id"] = 1) AND (c["$type"] = "DerivedSinglePartitionKeyEntity")) """); } @@ -424,7 +424,7 @@ public override async Task ReadItem_with_single_explicit_parameterized_discrimin SELECT VALUE c FROM root c -WHERE ((c["Id"] = 1) AND (c["Discriminator"] = @__discriminator_0)) +WHERE ((c["Id"] = 1) AND (c["$type"] = @__discriminator_0)) OFFSET 0 LIMIT 2 """); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryTestBase.cs b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryTestBase.cs index 74063fe7600..97c63f9a6ed 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryTestBase.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/ReadItemPartitionKeyQueryTestBase.cs @@ -342,7 +342,7 @@ public virtual Task ReadItem_with_single_explicit_discriminator_mapping() ss => ss.Set() .Where( e => e.Id == 1 - && EF.Property(e, "Discriminator") == nameof(SinglePartitionKeyEntity) + && EF.Property(e, "$type") == nameof(SinglePartitionKeyEntity) && e.PartitionKey == partitionKey), ss => ss.Set() .Where(e => e.Id == 1 && e.PartitionKey == partitionKey)); @@ -358,7 +358,7 @@ public virtual Task ReadItem_with_single_explicit_incorrect_discriminator_mappin ss => ss.Set() .Where( e => e.Id == 1 - && EF.Property(e, "Discriminator") == nameof(DerivedSinglePartitionKeyEntity) + && EF.Property(e, "$type") == nameof(DerivedSinglePartitionKeyEntity) && e.PartitionKey == partitionKey), ss => ss.Set().Where(e => false), assertEmpty: true); @@ -373,7 +373,7 @@ public virtual Task ReadItem_with_single_explicit_parameterized_discriminator_ma return AssertSingle( async: true, ss => ss.Set() - .Where(e => e.Id == 1 && EF.Property(e, "Discriminator") == discriminator && e.PartitionKey == partitionKey), + .Where(e => e.Id == 1 && EF.Property(e, "$type") == discriminator && e.PartitionKey == partitionKey), ss => ss.Set().Where(e => e.Id == 1 && e.PartitionKey == partitionKey)); } diff --git a/test/EFCore.Cosmos.FunctionalTests/ReloadTest.cs b/test/EFCore.Cosmos.FunctionalTests/ReloadTest.cs index 9efd9d08404..8dbd02287b5 100644 --- a/test/EFCore.Cosmos.FunctionalTests/ReloadTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/ReloadTest.cs @@ -44,7 +44,7 @@ SELECT VALUE { "Id" : c["Id"], "PartitionKey" : c["PartitionKey"], - "Discriminator" : c["Discriminator"], + "$type" : c["$type"], "id0" : c["id"], "" : c } diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/ManyTypesEntityType.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/ManyTypesEntityType.cs index eabb9f184eb..85405c4137f 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/ManyTypesEntityType.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/ManyTypesEntityType.cs @@ -37,7 +37,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas "Microsoft.EntityFrameworkCore.Scaffolding.CompiledModelTestBase+ManyTypes", typeof(CompiledModelTestBase.ManyTypes), baseEntityType, - discriminatorProperty: "Discriminator", + discriminatorProperty: "$type", discriminatorValue: "ManyTypes", propertyCount: 166, keyCount: 1); @@ -95,6 +95,39 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas id.SetCurrentValueComparer(new CurrentProviderValueComparer(id)); id.SetSentinelFromProviderValue(0); + var type = runtimeEntityType.AddProperty( + "$type", + typeof(string), + afterSaveBehavior: PropertySaveBehavior.Throw, + valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); + type.SetAccessors( + string (InternalEntityEntry entry) => entry.ReadShadowValue(0), + string (InternalEntityEntry entry) => entry.ReadShadowValue(0), + string (InternalEntityEntry entry) => entry.ReadOriginalValue(type, 1), + string (InternalEntityEntry entry) => entry.GetCurrentValue(type), + object (ValueBuffer valueBuffer) => valueBuffer[1]); + type.SetPropertyIndexes( + index: 1, + originalValueIndex: 1, + shadowIndex: 0, + relationshipIndex: -1, + storeGenerationIndex: -1); + type.TypeMapping = CosmosTypeMapping.Default.Clone( + comparer: new ValueComparer( + bool (string v1, string v2) => v1 == v2, + int (string v) => ((object)v).GetHashCode(), + string (string v) => v), + keyComparer: new ValueComparer( + bool (string v1, string v2) => v1 == v2, + int (string v) => ((object)v).GetHashCode(), + string (string v) => v), + providerValueComparer: new ValueComparer( + bool (string v1, string v2) => v1 == v2, + int (string v) => ((object)v).GetHashCode(), + string (string v) => v), + clrType: typeof(string), + jsonValueReaderWriter: JsonStringReaderWriter.Instance); + var @bool = runtimeEntityType.AddProperty( "Bool", typeof(bool), @@ -113,12 +146,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas @bool.SetAccessors( bool (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.Bool(((CompiledModelTestBase.ManyTypes)(entry.Entity))), bool (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.Bool(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - bool (InternalEntityEntry entry) => entry.ReadOriginalValue(@bool, 1), + bool (InternalEntityEntry entry) => entry.ReadOriginalValue(@bool, 2), bool (InternalEntityEntry entry) => entry.GetCurrentValue(@bool), - object (ValueBuffer valueBuffer) => valueBuffer[1]); + object (ValueBuffer valueBuffer) => valueBuffer[2]); @bool.SetPropertyIndexes( - index: 1, - originalValueIndex: 1, + index: 2, + originalValueIndex: 2, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -155,12 +188,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas boolArray.SetAccessors( bool[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolArray(((CompiledModelTestBase.ManyTypes)(entry.Entity))), bool[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolArray(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - bool[] (InternalEntityEntry entry) => entry.ReadOriginalValue(boolArray, 2), + bool[] (InternalEntityEntry entry) => entry.ReadOriginalValue(boolArray, 3), bool[] (InternalEntityEntry entry) => entry.GetCurrentValue(boolArray), - object (ValueBuffer valueBuffer) => valueBuffer[2]); + object (ValueBuffer valueBuffer) => valueBuffer[3]); boolArray.SetPropertyIndexes( - index: 2, - originalValueIndex: 2, + index: 3, + originalValueIndex: 3, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -213,12 +246,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas boolNestedCollection.SetAccessors( bool[][] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolNestedCollection(((CompiledModelTestBase.ManyTypes)(entry.Entity))), bool[][] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolNestedCollection(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - bool[][] (InternalEntityEntry entry) => entry.ReadOriginalValue(boolNestedCollection, 3), + bool[][] (InternalEntityEntry entry) => entry.ReadOriginalValue(boolNestedCollection, 4), bool[][] (InternalEntityEntry entry) => entry.GetCurrentValue(boolNestedCollection), - object (ValueBuffer valueBuffer) => valueBuffer[3]); + object (ValueBuffer valueBuffer) => valueBuffer[4]); boolNestedCollection.SetPropertyIndexes( - index: 3, - originalValueIndex: 3, + index: 4, + originalValueIndex: 4, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -288,12 +321,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas boolToStringConverterProperty.SetAccessors( bool (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), bool (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - bool (InternalEntityEntry entry) => entry.ReadOriginalValue(boolToStringConverterProperty, 4), + bool (InternalEntityEntry entry) => entry.ReadOriginalValue(boolToStringConverterProperty, 5), bool (InternalEntityEntry entry) => entry.GetCurrentValue(boolToStringConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[4]); + object (ValueBuffer valueBuffer) => valueBuffer[5]); boolToStringConverterProperty.SetPropertyIndexes( - index: 4, - originalValueIndex: 4, + index: 5, + originalValueIndex: 5, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -337,12 +370,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas boolToTwoValuesConverterProperty.SetAccessors( bool (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolToTwoValuesConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), bool (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolToTwoValuesConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - bool (InternalEntityEntry entry) => entry.ReadOriginalValue(boolToTwoValuesConverterProperty, 5), + bool (InternalEntityEntry entry) => entry.ReadOriginalValue(boolToTwoValuesConverterProperty, 6), bool (InternalEntityEntry entry) => entry.GetCurrentValue(boolToTwoValuesConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[5]); + object (ValueBuffer valueBuffer) => valueBuffer[6]); boolToTwoValuesConverterProperty.SetPropertyIndexes( - index: 5, - originalValueIndex: 5, + index: 6, + originalValueIndex: 6, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -387,12 +420,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas boolToZeroOneConverterProperty.SetAccessors( bool (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolToZeroOneConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), bool (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BoolToZeroOneConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - bool (InternalEntityEntry entry) => entry.ReadOriginalValue(boolToZeroOneConverterProperty, 6), + bool (InternalEntityEntry entry) => entry.ReadOriginalValue(boolToZeroOneConverterProperty, 7), bool (InternalEntityEntry entry) => entry.GetCurrentValue(boolToZeroOneConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[6]); + object (ValueBuffer valueBuffer) => valueBuffer[7]); boolToZeroOneConverterProperty.SetPropertyIndexes( - index: 6, - originalValueIndex: 6, + index: 7, + originalValueIndex: 7, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -436,12 +469,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas bytes.SetAccessors( byte[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.Bytes(((CompiledModelTestBase.ManyTypes)(entry.Entity))), byte[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.Bytes(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - byte[] (InternalEntityEntry entry) => entry.ReadOriginalValue(bytes, 7), + byte[] (InternalEntityEntry entry) => entry.ReadOriginalValue(bytes, 8), byte[] (InternalEntityEntry entry) => entry.GetCurrentValue(bytes), - object (ValueBuffer valueBuffer) => valueBuffer[7]); + object (ValueBuffer valueBuffer) => valueBuffer[8]); bytes.SetPropertyIndexes( - index: 7, - originalValueIndex: 7, + index: 8, + originalValueIndex: 8, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -486,12 +519,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas bytesToStringConverterProperty.SetAccessors( byte[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BytesToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), byte[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.BytesToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - byte[] (InternalEntityEntry entry) => entry.ReadOriginalValue(bytesToStringConverterProperty, 8), + byte[] (InternalEntityEntry entry) => entry.ReadOriginalValue(bytesToStringConverterProperty, 9), byte[] (InternalEntityEntry entry) => entry.GetCurrentValue(bytesToStringConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[8]); + object (ValueBuffer valueBuffer) => valueBuffer[9]); bytesToStringConverterProperty.SetPropertyIndexes( - index: 8, - originalValueIndex: 8, + index: 9, + originalValueIndex: 9, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -535,12 +568,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas castingConverterProperty.SetAccessors( int (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.CastingConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), int (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.CastingConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - int (InternalEntityEntry entry) => entry.ReadOriginalValue(castingConverterProperty, 9), + int (InternalEntityEntry entry) => entry.ReadOriginalValue(castingConverterProperty, 10), int (InternalEntityEntry entry) => entry.GetCurrentValue(castingConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[9]); + object (ValueBuffer valueBuffer) => valueBuffer[10]); castingConverterProperty.SetPropertyIndexes( - index: 9, - originalValueIndex: 9, + index: 10, + originalValueIndex: 10, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -585,12 +618,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas @char.SetAccessors( char (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.Char(((CompiledModelTestBase.ManyTypes)(entry.Entity))), char (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.Char(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - char (InternalEntityEntry entry) => entry.ReadOriginalValue(@char, 10), + char (InternalEntityEntry entry) => entry.ReadOriginalValue(@char, 11), char (InternalEntityEntry entry) => entry.GetCurrentValue(@char), - object (ValueBuffer valueBuffer) => valueBuffer[10]); + object (ValueBuffer valueBuffer) => valueBuffer[11]); @char.SetPropertyIndexes( - index: 10, - originalValueIndex: 10, + index: 11, + originalValueIndex: 11, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -627,12 +660,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas charArray.SetAccessors( char[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.CharArray(((CompiledModelTestBase.ManyTypes)(entry.Entity))), char[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.CharArray(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - char[] (InternalEntityEntry entry) => entry.ReadOriginalValue(charArray, 11), + char[] (InternalEntityEntry entry) => entry.ReadOriginalValue(charArray, 12), char[] (InternalEntityEntry entry) => entry.GetCurrentValue(charArray), - object (ValueBuffer valueBuffer) => valueBuffer[11]); + object (ValueBuffer valueBuffer) => valueBuffer[12]); charArray.SetPropertyIndexes( - index: 11, - originalValueIndex: 11, + index: 12, + originalValueIndex: 12, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -685,12 +718,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas charNestedCollection.SetAccessors( char[][] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.CharNestedCollection(((CompiledModelTestBase.ManyTypes)(entry.Entity))), char[][] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.CharNestedCollection(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - char[][] (InternalEntityEntry entry) => entry.ReadOriginalValue(charNestedCollection, 12), + char[][] (InternalEntityEntry entry) => entry.ReadOriginalValue(charNestedCollection, 13), char[][] (InternalEntityEntry entry) => entry.GetCurrentValue(charNestedCollection), - object (ValueBuffer valueBuffer) => valueBuffer[12]); + object (ValueBuffer valueBuffer) => valueBuffer[13]); charNestedCollection.SetPropertyIndexes( - index: 12, - originalValueIndex: 12, + index: 13, + originalValueIndex: 13, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -761,12 +794,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas charToStringConverterProperty.SetAccessors( char (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.CharToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), char (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.CharToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - char (InternalEntityEntry entry) => entry.ReadOriginalValue(charToStringConverterProperty, 13), + char (InternalEntityEntry entry) => entry.ReadOriginalValue(charToStringConverterProperty, 14), char (InternalEntityEntry entry) => entry.GetCurrentValue(charToStringConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[13]); + object (ValueBuffer valueBuffer) => valueBuffer[14]); charToStringConverterProperty.SetPropertyIndexes( - index: 13, - originalValueIndex: 13, + index: 14, + originalValueIndex: 14, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -811,12 +844,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateOnly.SetAccessors( DateOnly (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateOnly(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateOnly (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateOnly(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateOnly (InternalEntityEntry entry) => entry.ReadOriginalValue(dateOnly, 14), + DateOnly (InternalEntityEntry entry) => entry.ReadOriginalValue(dateOnly, 15), DateOnly (InternalEntityEntry entry) => entry.GetCurrentValue(dateOnly), - object (ValueBuffer valueBuffer) => valueBuffer[14]); + object (ValueBuffer valueBuffer) => valueBuffer[15]); dateOnly.SetPropertyIndexes( - index: 14, - originalValueIndex: 14, + index: 15, + originalValueIndex: 15, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -854,12 +887,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateOnlyToStringConverterProperty.SetAccessors( DateOnly (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateOnlyToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateOnly (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateOnlyToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateOnly (InternalEntityEntry entry) => entry.ReadOriginalValue(dateOnlyToStringConverterProperty, 15), + DateOnly (InternalEntityEntry entry) => entry.ReadOriginalValue(dateOnlyToStringConverterProperty, 16), DateOnly (InternalEntityEntry entry) => entry.GetCurrentValue(dateOnlyToStringConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[15]); + object (ValueBuffer valueBuffer) => valueBuffer[16]); dateOnlyToStringConverterProperty.SetPropertyIndexes( - index: 15, - originalValueIndex: 15, + index: 16, + originalValueIndex: 16, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -904,12 +937,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateTime.SetAccessors( DateTime (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTime(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateTime (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTime(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateTime (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTime, 16), + DateTime (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTime, 17), DateTime (InternalEntityEntry entry) => entry.GetCurrentValue(dateTime), - object (ValueBuffer valueBuffer) => valueBuffer[16]); + object (ValueBuffer valueBuffer) => valueBuffer[17]); dateTime.SetPropertyIndexes( - index: 16, - originalValueIndex: 16, + index: 17, + originalValueIndex: 17, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -947,12 +980,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateTimeOffsetToBinaryConverterProperty.SetAccessors( DateTimeOffset (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeOffsetToBinaryConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateTimeOffset (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeOffsetToBinaryConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateTimeOffset (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeOffsetToBinaryConverterProperty, 17), + DateTimeOffset (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeOffsetToBinaryConverterProperty, 18), DateTimeOffset (InternalEntityEntry entry) => entry.GetCurrentValue(dateTimeOffsetToBinaryConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[17]); + object (ValueBuffer valueBuffer) => valueBuffer[18]); dateTimeOffsetToBinaryConverterProperty.SetPropertyIndexes( - index: 17, - originalValueIndex: 17, + index: 18, + originalValueIndex: 18, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -997,12 +1030,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateTimeOffsetToBytesConverterProperty.SetAccessors( DateTimeOffset (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeOffsetToBytesConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateTimeOffset (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeOffsetToBytesConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateTimeOffset (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeOffsetToBytesConverterProperty, 18), + DateTimeOffset (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeOffsetToBytesConverterProperty, 19), DateTimeOffset (InternalEntityEntry entry) => entry.GetCurrentValue(dateTimeOffsetToBytesConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[18]); + object (ValueBuffer valueBuffer) => valueBuffer[19]); dateTimeOffsetToBytesConverterProperty.SetPropertyIndexes( - index: 18, - originalValueIndex: 18, + index: 19, + originalValueIndex: 19, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1047,12 +1080,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateTimeOffsetToStringConverterProperty.SetAccessors( DateTimeOffset (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeOffsetToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateTimeOffset (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeOffsetToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateTimeOffset (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeOffsetToStringConverterProperty, 19), + DateTimeOffset (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeOffsetToStringConverterProperty, 20), DateTimeOffset (InternalEntityEntry entry) => entry.GetCurrentValue(dateTimeOffsetToStringConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[19]); + object (ValueBuffer valueBuffer) => valueBuffer[20]); dateTimeOffsetToStringConverterProperty.SetPropertyIndexes( - index: 19, - originalValueIndex: 19, + index: 20, + originalValueIndex: 20, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1097,12 +1130,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateTimeToBinaryConverterProperty.SetAccessors( DateTime (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeToBinaryConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateTime (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeToBinaryConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateTime (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeToBinaryConverterProperty, 20), + DateTime (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeToBinaryConverterProperty, 21), DateTime (InternalEntityEntry entry) => entry.GetCurrentValue(dateTimeToBinaryConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[20]); + object (ValueBuffer valueBuffer) => valueBuffer[21]); dateTimeToBinaryConverterProperty.SetPropertyIndexes( - index: 20, - originalValueIndex: 20, + index: 21, + originalValueIndex: 21, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1147,12 +1180,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateTimeToStringConverterProperty.SetAccessors( DateTime (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateTime (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateTime (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeToStringConverterProperty, 21), + DateTime (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeToStringConverterProperty, 22), DateTime (InternalEntityEntry entry) => entry.GetCurrentValue(dateTimeToStringConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[21]); + object (ValueBuffer valueBuffer) => valueBuffer[22]); dateTimeToStringConverterProperty.SetPropertyIndexes( - index: 21, - originalValueIndex: 21, + index: 22, + originalValueIndex: 22, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1197,12 +1230,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas dateTimeToTicksConverterProperty.SetAccessors( DateTime (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeToTicksConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), DateTime (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DateTimeToTicksConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - DateTime (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeToTicksConverterProperty, 22), + DateTime (InternalEntityEntry entry) => entry.ReadOriginalValue(dateTimeToTicksConverterProperty, 23), DateTime (InternalEntityEntry entry) => entry.GetCurrentValue(dateTimeToTicksConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[22]); + object (ValueBuffer valueBuffer) => valueBuffer[23]); dateTimeToTicksConverterProperty.SetPropertyIndexes( - index: 22, - originalValueIndex: 22, + index: 23, + originalValueIndex: 23, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1240,12 +1273,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas @decimal.SetAccessors( decimal (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.Decimal(((CompiledModelTestBase.ManyTypes)(entry.Entity))), decimal (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.Decimal(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - decimal (InternalEntityEntry entry) => entry.ReadOriginalValue(@decimal, 23), + decimal (InternalEntityEntry entry) => entry.ReadOriginalValue(@decimal, 24), decimal (InternalEntityEntry entry) => entry.GetCurrentValue(@decimal), - object (ValueBuffer valueBuffer) => valueBuffer[23]); + object (ValueBuffer valueBuffer) => valueBuffer[24]); @decimal.SetPropertyIndexes( - index: 23, - originalValueIndex: 23, + index: 24, + originalValueIndex: 24, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1282,12 +1315,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas decimalArray.SetAccessors( decimal[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DecimalArray(((CompiledModelTestBase.ManyTypes)(entry.Entity))), decimal[] (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DecimalArray(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - decimal[] (InternalEntityEntry entry) => entry.ReadOriginalValue(decimalArray, 24), + decimal[] (InternalEntityEntry entry) => entry.ReadOriginalValue(decimalArray, 25), decimal[] (InternalEntityEntry entry) => entry.GetCurrentValue(decimalArray), - object (ValueBuffer valueBuffer) => valueBuffer[24]); + object (ValueBuffer valueBuffer) => valueBuffer[25]); decimalArray.SetPropertyIndexes( - index: 24, - originalValueIndex: 24, + index: 25, + originalValueIndex: 25, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1341,12 +1374,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas decimalNumberToBytesConverterProperty.SetAccessors( decimal (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DecimalNumberToBytesConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), decimal (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DecimalNumberToBytesConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - decimal (InternalEntityEntry entry) => entry.ReadOriginalValue(decimalNumberToBytesConverterProperty, 25), + decimal (InternalEntityEntry entry) => entry.ReadOriginalValue(decimalNumberToBytesConverterProperty, 26), decimal (InternalEntityEntry entry) => entry.GetCurrentValue(decimalNumberToBytesConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[25]); + object (ValueBuffer valueBuffer) => valueBuffer[26]); decimalNumberToBytesConverterProperty.SetPropertyIndexes( - index: 25, - originalValueIndex: 25, + index: 26, + originalValueIndex: 26, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1391,12 +1424,12 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas decimalNumberToStringConverterProperty.SetAccessors( decimal (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DecimalNumberToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), decimal (InternalEntityEntry entry) => ManyTypesUnsafeAccessors.DecimalNumberToStringConverterProperty(((CompiledModelTestBase.ManyTypes)(entry.Entity))), - decimal (InternalEntityEntry entry) => entry.ReadOriginalValue(decimalNumberToStringConverterProperty, 26), + decimal (InternalEntityEntry entry) => entry.ReadOriginalValue(decimalNumberToStringConverterProperty, 27), decimal (InternalEntityEntry entry) => entry.GetCurrentValue(decimalNumberToStringConverterProperty), - object (ValueBuffer valueBuffer) => valueBuffer[26]); + object (ValueBuffer valueBuffer) => valueBuffer[27]); decimalNumberToStringConverterProperty.SetPropertyIndexes( - index: 26, - originalValueIndex: 26, + index: 27, + originalValueIndex: 27, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); @@ -1423,39 +1456,6 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas decimal (string v) => decimal.Parse(v, NumberStyles.Any, CultureInfo.InvariantCulture)))); decimalNumberToStringConverterProperty.SetSentinelFromProviderValue("0"); - var discriminator = runtimeEntityType.AddProperty( - "Discriminator", - typeof(string), - afterSaveBehavior: PropertySaveBehavior.Throw, - valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); - discriminator.SetAccessors( - string (InternalEntityEntry entry) => entry.ReadShadowValue(0), - string (InternalEntityEntry entry) => entry.ReadShadowValue(0), - string (InternalEntityEntry entry) => entry.ReadOriginalValue(discriminator, 27), - string (InternalEntityEntry entry) => entry.GetCurrentValue(discriminator), - object (ValueBuffer valueBuffer) => valueBuffer[27]); - discriminator.SetPropertyIndexes( - index: 27, - originalValueIndex: 27, - shadowIndex: 0, - relationshipIndex: -1, - storeGenerationIndex: -1); - discriminator.TypeMapping = CosmosTypeMapping.Default.Clone( - comparer: new ValueComparer( - bool (string v1, string v2) => v1 == v2, - int (string v) => ((object)v).GetHashCode(), - string (string v) => v), - keyComparer: new ValueComparer( - bool (string v1, string v2) => v1 == v2, - int (string v) => ((object)v).GetHashCode(), - string (string v) => v), - providerValueComparer: new ValueComparer( - bool (string v1, string v2) => v1 == v2, - int (string v) => ((object)v).GetHashCode(), - string (string v) => v), - clrType: typeof(string), - jsonValueReaderWriter: JsonStringReaderWriter.Instance); - var @double = runtimeEntityType.AddProperty( "Double", typeof(double), @@ -8544,6 +8544,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { var id = runtimeEntityType.FindProperty("Id")!; + var type = runtimeEntityType.FindProperty("$type")!; var @bool = runtimeEntityType.FindProperty("Bool")!; var boolArray = runtimeEntityType.FindProperty("BoolArray")!; var boolNestedCollection = runtimeEntityType.FindProperty("BoolNestedCollection")!; @@ -8570,7 +8571,6 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) var decimalArray = runtimeEntityType.FindProperty("DecimalArray")!; var decimalNumberToBytesConverterProperty = runtimeEntityType.FindProperty("DecimalNumberToBytesConverterProperty")!; var decimalNumberToStringConverterProperty = runtimeEntityType.FindProperty("DecimalNumberToStringConverterProperty")!; - var discriminator = runtimeEntityType.FindProperty("Discriminator")!; var @double = runtimeEntityType.FindProperty("Double")!; var doubleArray = runtimeEntityType.FindProperty("DoubleArray")!; var doubleNumberToBytesConverterProperty = runtimeEntityType.FindProperty("DoubleNumberToBytesConverterProperty")!; @@ -8716,7 +8716,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) ISnapshot (InternalEntityEntry source) => { var entity = ((CompiledModelTestBase.ManyTypes)(source.Entity)); - var liftedArg = ((ISnapshot)(new Snapshot(((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id)), ((ValueComparer)(((IProperty)@bool).GetValueComparer())).Snapshot(source.GetCurrentValue(@bool)), (((IEnumerable)(source.GetCurrentValue(boolArray))) == null ? null : ((bool[])(((ValueComparer>)(((IProperty)boolArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(boolArray))))))), (((object)(source.GetCurrentValue(boolNestedCollection))) == null ? null : ((bool[][])(((ValueComparer)(((IProperty)boolNestedCollection).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue(boolNestedCollection))))))), ((ValueComparer)(((IProperty)boolToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(boolToStringConverterProperty)), ((ValueComparer)(((IProperty)boolToTwoValuesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(boolToTwoValuesConverterProperty)), ((ValueComparer)(((IProperty)boolToZeroOneConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(boolToZeroOneConverterProperty)), (source.GetCurrentValue(bytes) == null ? null : ((ValueComparer)(((IProperty)bytes).GetValueComparer())).Snapshot(source.GetCurrentValue(bytes))), (source.GetCurrentValue(bytesToStringConverterProperty) == null ? null : ((ValueComparer)(((IProperty)bytesToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(bytesToStringConverterProperty))), ((ValueComparer)(((IProperty)castingConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(castingConverterProperty)), ((ValueComparer)(((IProperty)@char).GetValueComparer())).Snapshot(source.GetCurrentValue(@char)), (((IEnumerable)(source.GetCurrentValue(charArray))) == null ? null : ((char[])(((ValueComparer>)(((IProperty)charArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(charArray))))))), (((object)(source.GetCurrentValue(charNestedCollection))) == null ? null : ((char[][])(((ValueComparer)(((IProperty)charNestedCollection).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue(charNestedCollection))))))), ((ValueComparer)(((IProperty)charToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(charToStringConverterProperty)), ((ValueComparer)(((IProperty)dateOnly).GetValueComparer())).Snapshot(source.GetCurrentValue(dateOnly)), ((ValueComparer)(((IProperty)dateOnlyToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateOnlyToStringConverterProperty)), ((ValueComparer)(((IProperty)dateTime).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTime)), ((ValueComparer)(((IProperty)dateTimeOffsetToBinaryConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeOffsetToBinaryConverterProperty)), ((ValueComparer)(((IProperty)dateTimeOffsetToBytesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeOffsetToBytesConverterProperty)), ((ValueComparer)(((IProperty)dateTimeOffsetToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeOffsetToStringConverterProperty)), ((ValueComparer)(((IProperty)dateTimeToBinaryConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeToBinaryConverterProperty)), ((ValueComparer)(((IProperty)dateTimeToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeToStringConverterProperty)), ((ValueComparer)(((IProperty)dateTimeToTicksConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeToTicksConverterProperty)), ((ValueComparer)(((IProperty)@decimal).GetValueComparer())).Snapshot(source.GetCurrentValue(@decimal)), (((IEnumerable)(source.GetCurrentValue(decimalArray))) == null ? null : ((decimal[])(((ValueComparer>)(((IProperty)decimalArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(decimalArray))))))), ((ValueComparer)(((IProperty)decimalNumberToBytesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(decimalNumberToBytesConverterProperty)), ((ValueComparer)(((IProperty)decimalNumberToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(decimalNumberToStringConverterProperty)), (source.GetCurrentValue(discriminator) == null ? null : ((ValueComparer)(((IProperty)discriminator).GetValueComparer())).Snapshot(source.GetCurrentValue(discriminator))), ((ValueComparer)(((IProperty)@double).GetValueComparer())).Snapshot(source.GetCurrentValue(@double)), (((IEnumerable)(source.GetCurrentValue(doubleArray))) == null ? null : ((double[])(((ValueComparer>)(((IProperty)doubleArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(doubleArray)))))))))); + var liftedArg = ((ISnapshot)(new Snapshot(((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id)), (source.GetCurrentValue(type) == null ? null : ((ValueComparer)(((IProperty)type).GetValueComparer())).Snapshot(source.GetCurrentValue(type))), ((ValueComparer)(((IProperty)@bool).GetValueComparer())).Snapshot(source.GetCurrentValue(@bool)), (((IEnumerable)(source.GetCurrentValue(boolArray))) == null ? null : ((bool[])(((ValueComparer>)(((IProperty)boolArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(boolArray))))))), (((object)(source.GetCurrentValue(boolNestedCollection))) == null ? null : ((bool[][])(((ValueComparer)(((IProperty)boolNestedCollection).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue(boolNestedCollection))))))), ((ValueComparer)(((IProperty)boolToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(boolToStringConverterProperty)), ((ValueComparer)(((IProperty)boolToTwoValuesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(boolToTwoValuesConverterProperty)), ((ValueComparer)(((IProperty)boolToZeroOneConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(boolToZeroOneConverterProperty)), (source.GetCurrentValue(bytes) == null ? null : ((ValueComparer)(((IProperty)bytes).GetValueComparer())).Snapshot(source.GetCurrentValue(bytes))), (source.GetCurrentValue(bytesToStringConverterProperty) == null ? null : ((ValueComparer)(((IProperty)bytesToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(bytesToStringConverterProperty))), ((ValueComparer)(((IProperty)castingConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(castingConverterProperty)), ((ValueComparer)(((IProperty)@char).GetValueComparer())).Snapshot(source.GetCurrentValue(@char)), (((IEnumerable)(source.GetCurrentValue(charArray))) == null ? null : ((char[])(((ValueComparer>)(((IProperty)charArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(charArray))))))), (((object)(source.GetCurrentValue(charNestedCollection))) == null ? null : ((char[][])(((ValueComparer)(((IProperty)charNestedCollection).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue(charNestedCollection))))))), ((ValueComparer)(((IProperty)charToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(charToStringConverterProperty)), ((ValueComparer)(((IProperty)dateOnly).GetValueComparer())).Snapshot(source.GetCurrentValue(dateOnly)), ((ValueComparer)(((IProperty)dateOnlyToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateOnlyToStringConverterProperty)), ((ValueComparer)(((IProperty)dateTime).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTime)), ((ValueComparer)(((IProperty)dateTimeOffsetToBinaryConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeOffsetToBinaryConverterProperty)), ((ValueComparer)(((IProperty)dateTimeOffsetToBytesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeOffsetToBytesConverterProperty)), ((ValueComparer)(((IProperty)dateTimeOffsetToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeOffsetToStringConverterProperty)), ((ValueComparer)(((IProperty)dateTimeToBinaryConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeToBinaryConverterProperty)), ((ValueComparer)(((IProperty)dateTimeToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeToStringConverterProperty)), ((ValueComparer)(((IProperty)dateTimeToTicksConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(dateTimeToTicksConverterProperty)), ((ValueComparer)(((IProperty)@decimal).GetValueComparer())).Snapshot(source.GetCurrentValue(@decimal)), (((IEnumerable)(source.GetCurrentValue(decimalArray))) == null ? null : ((decimal[])(((ValueComparer>)(((IProperty)decimalArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(decimalArray))))))), ((ValueComparer)(((IProperty)decimalNumberToBytesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(decimalNumberToBytesConverterProperty)), ((ValueComparer)(((IProperty)decimalNumberToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(decimalNumberToStringConverterProperty)), ((ValueComparer)(((IProperty)@double).GetValueComparer())).Snapshot(source.GetCurrentValue(@double)), (((IEnumerable)(source.GetCurrentValue(doubleArray))) == null ? null : ((double[])(((ValueComparer>)(((IProperty)doubleArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(doubleArray)))))))))); var entity0 = ((CompiledModelTestBase.ManyTypes)(source.Entity)); var liftedArg0 = ((ISnapshot)(new Snapshot(((ValueComparer)(((IProperty)doubleNumberToBytesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(doubleNumberToBytesConverterProperty)), ((ValueComparer)(((IProperty)doubleNumberToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(doubleNumberToStringConverterProperty)), ((ValueComparer)(((IProperty)enum16).GetValueComparer())).Snapshot(source.GetCurrentValue(enum16)), ((ValueComparer)(((IProperty)enum16AsString).GetValueComparer())).Snapshot(source.GetCurrentValue(enum16AsString)), ((ValueComparer)(((IProperty)enum32).GetValueComparer())).Snapshot(source.GetCurrentValue(enum32)), ((ValueComparer)(((IProperty)enum32AsString).GetValueComparer())).Snapshot(source.GetCurrentValue(enum32AsString)), ((ValueComparer)(((IProperty)enum64).GetValueComparer())).Snapshot(source.GetCurrentValue(enum64)), ((ValueComparer)(((IProperty)enum64AsString).GetValueComparer())).Snapshot(source.GetCurrentValue(enum64AsString)), ((ValueComparer)(((IProperty)enum8).GetValueComparer())).Snapshot(source.GetCurrentValue(enum8)), ((ValueComparer)(((IProperty)enum8AsString).GetValueComparer())).Snapshot(source.GetCurrentValue(enum8AsString)), ((ValueComparer)(((IProperty)enumToNumberConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(enumToNumberConverterProperty)), ((ValueComparer)(((IProperty)enumToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(enumToStringConverterProperty)), ((ValueComparer)(((IProperty)enumU16).GetValueComparer())).Snapshot(source.GetCurrentValue(enumU16)), ((ValueComparer)(((IProperty)enumU16AsString).GetValueComparer())).Snapshot(source.GetCurrentValue(enumU16AsString)), ((ValueComparer)(((IProperty)enumU32).GetValueComparer())).Snapshot(source.GetCurrentValue(enumU32)), ((ValueComparer)(((IProperty)enumU32AsString).GetValueComparer())).Snapshot(source.GetCurrentValue(enumU32AsString)), ((ValueComparer)(((IProperty)enumU64).GetValueComparer())).Snapshot(source.GetCurrentValue(enumU64)), ((ValueComparer)(((IProperty)enumU64AsString).GetValueComparer())).Snapshot(source.GetCurrentValue(enumU64AsString)), ((ValueComparer)(((IProperty)enumU8).GetValueComparer())).Snapshot(source.GetCurrentValue(enumU8)), ((ValueComparer)(((IProperty)enumU8AsString).GetValueComparer())).Snapshot(source.GetCurrentValue(enumU8AsString)), ((ValueComparer)(((IProperty)@float).GetValueComparer())).Snapshot(source.GetCurrentValue(@float)), (((IEnumerable)(source.GetCurrentValue(floatArray))) == null ? null : ((float[])(((ValueComparer>)(((IProperty)floatArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(floatArray))))))), ((ValueComparer)(((IProperty)guid).GetValueComparer())).Snapshot(source.GetCurrentValue(guid)), ((ValueComparer)(((IProperty)guidToBytesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(guidToBytesConverterProperty)), ((ValueComparer)(((IProperty)guidToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(guidToStringConverterProperty)), (source.GetCurrentValue(iPAddress) == null ? null : ((ValueComparer)(((IProperty)iPAddress).GetValueComparer())).Snapshot(source.GetCurrentValue(iPAddress))), (source.GetCurrentValue(iPAddressToBytesConverterProperty) == null ? null : ((ValueComparer)(((IProperty)iPAddressToBytesConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(iPAddressToBytesConverterProperty))), (source.GetCurrentValue(iPAddressToStringConverterProperty) == null ? null : ((ValueComparer)(((IProperty)iPAddressToStringConverterProperty).GetValueComparer())).Snapshot(source.GetCurrentValue(iPAddressToStringConverterProperty))), ((ValueComparer)(((IProperty)int16).GetValueComparer())).Snapshot(source.GetCurrentValue(int16)), (((IEnumerable)(source.GetCurrentValue(int16Array))) == null ? null : ((short[])(((ValueComparer>)(((IProperty)int16Array).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(int16Array)))))))))); var entity1 = ((CompiledModelTestBase.ManyTypes)(source.Entity)); @@ -8733,7 +8733,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) runtimeEntityType.SetTemporaryValuesFactory( ISnapshot (InternalEntityEntry source) => ((ISnapshot)(new Snapshot(default(CompiledModelTestBase.ManyTypesId), default(JObject))))); runtimeEntityType.SetShadowValuesFactory( - ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("Discriminator") ? ((string)(source["Discriminator"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); + ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("$type") ? ((string)(source["$type"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); runtimeEntityType.SetEmptyShadowValuesFactory( ISnapshot () => ((ISnapshot)(new Snapshot(default(string), default(string), default(JObject))))); runtimeEntityType.SetRelationshipSnapshotFactory( diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalBaseEntityType.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalBaseEntityType.cs index 33723132020..aec8bc43c35 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalBaseEntityType.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalBaseEntityType.cs @@ -33,7 +33,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas "Microsoft.EntityFrameworkCore.Scaffolding.CompiledModelTestBase+PrincipalBase", typeof(CompiledModelTestBase.PrincipalBase), baseEntityType, - discriminatorProperty: "Discriminator", + discriminatorProperty: "$type", discriminatorValue: "PrincipalBase", derivedTypesCount: 1, propertyCount: 15, @@ -135,24 +135,24 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas alternateId.SetCurrentValueComparer(new EntryCurrentValueComparer(alternateId)); alternateId.SetSentinelFromProviderValue("00000000-0000-0000-0000-000000000000"); - var discriminator = runtimeEntityType.AddProperty( - "Discriminator", + var type = runtimeEntityType.AddProperty( + "$type", typeof(string), afterSaveBehavior: PropertySaveBehavior.Throw, valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); - discriminator.SetAccessors( + type.SetAccessors( string (InternalEntityEntry entry) => entry.ReadShadowValue(0), string (InternalEntityEntry entry) => entry.ReadShadowValue(0), - string (InternalEntityEntry entry) => entry.ReadOriginalValue(discriminator, 2), - string (InternalEntityEntry entry) => entry.GetCurrentValue(discriminator), + string (InternalEntityEntry entry) => entry.ReadOriginalValue(type, 2), + string (InternalEntityEntry entry) => entry.GetCurrentValue(type), object (ValueBuffer valueBuffer) => valueBuffer[2]); - discriminator.SetPropertyIndexes( + type.SetPropertyIndexes( index: 2, originalValueIndex: 2, shadowIndex: 0, relationshipIndex: -1, storeGenerationIndex: -1); - discriminator.TypeMapping = CosmosTypeMapping.Default.Clone( + type.TypeMapping = CosmosTypeMapping.Default.Clone( comparer: new ValueComparer( bool (string v1, string v2) => v1 == v2, int (string v) => ((object)v).GetHashCode(), @@ -853,7 +853,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { var id = runtimeEntityType.FindProperty("Id")!; var alternateId = runtimeEntityType.FindProperty("AlternateId")!; - var discriminator = runtimeEntityType.FindProperty("Discriminator")!; + var type = runtimeEntityType.FindProperty("$type")!; var enum1 = runtimeEntityType.FindProperty("Enum1")!; var enum2 = runtimeEntityType.FindProperty("Enum2")!; var flagsEnum1 = runtimeEntityType.FindProperty("FlagsEnum1")!; @@ -877,14 +877,14 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) ISnapshot (InternalEntityEntry source) => { var entity5 = ((CompiledModelTestBase.PrincipalBase)(source.Entity)); - return ((ISnapshot)(new Snapshot, IList, DateTime[], IEnumerable, IList, List, string, JObject>((source.GetCurrentValue(id) == null ? null : ((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id))), ((ValueComparer)(((IProperty)alternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(alternateId)), (source.GetCurrentValue(discriminator) == null ? null : ((ValueComparer)(((IProperty)discriminator).GetValueComparer())).Snapshot(source.GetCurrentValue(discriminator))), ((ValueComparer)(((IProperty)enum1).GetValueComparer())).Snapshot(source.GetCurrentValue(enum1)), (source.GetCurrentValue(enum2) == null ? null : ((ValueComparer)(((IProperty)enum2).GetValueComparer())).Snapshot(source.GetCurrentValue(enum2))), ((ValueComparer)(((IProperty)flagsEnum1).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum1)), ((ValueComparer)(((IProperty)flagsEnum2).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum2)), (((object)(source.GetCurrentValue>(refTypeEnumerable))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable))))))), (((object)(source.GetCurrentValue>(refTypeIList))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray))))))), (source.GetCurrentValue>(valueTypeEnumerable) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList))))))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject)))))); + return ((ISnapshot)(new Snapshot, IList, DateTime[], IEnumerable, IList, List, string, JObject>((source.GetCurrentValue(id) == null ? null : ((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id))), ((ValueComparer)(((IProperty)alternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(alternateId)), (source.GetCurrentValue(type) == null ? null : ((ValueComparer)(((IProperty)type).GetValueComparer())).Snapshot(source.GetCurrentValue(type))), ((ValueComparer)(((IProperty)enum1).GetValueComparer())).Snapshot(source.GetCurrentValue(enum1)), (source.GetCurrentValue(enum2) == null ? null : ((ValueComparer)(((IProperty)enum2).GetValueComparer())).Snapshot(source.GetCurrentValue(enum2))), ((ValueComparer)(((IProperty)flagsEnum1).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum1)), ((ValueComparer)(((IProperty)flagsEnum2).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum2)), (((object)(source.GetCurrentValue>(refTypeEnumerable))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable))))))), (((object)(source.GetCurrentValue>(refTypeIList))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray))))))), (source.GetCurrentValue>(valueTypeEnumerable) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList))))))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject)))))); }); runtimeEntityType.SetStoreGeneratedValuesFactory( ISnapshot () => Snapshot.Empty); runtimeEntityType.SetTemporaryValuesFactory( ISnapshot (InternalEntityEntry source) => Snapshot.Empty); runtimeEntityType.SetShadowValuesFactory( - ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("Discriminator") ? ((string)(source["Discriminator"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); + ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("$type") ? ((string)(source["$type"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); runtimeEntityType.SetEmptyShadowValuesFactory( ISnapshot () => ((ISnapshot)(new Snapshot(default(string), default(string), default(JObject))))); runtimeEntityType.SetRelationshipSnapshotFactory( diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalBasePrincipalDerivedDependentBasebyteEntityType.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalBasePrincipalDerivedDependentBasebyteEntityType.cs index 60a7d470558..8cb4a6311c0 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalBasePrincipalDerivedDependentBasebyteEntityType.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalBasePrincipalDerivedDependentBasebyteEntityType.cs @@ -33,7 +33,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas typeof(Dictionary), baseEntityType, sharedClrType: true, - discriminatorProperty: "Discriminator", + discriminatorProperty: "$type", indexerPropertyInfo: RuntimeEntityType.FindIndexerProperty(typeof(Dictionary)), propertyBag: true, discriminatorValue: "PrincipalBasePrincipalDerived>", @@ -321,34 +321,34 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas Guid (string v) => new Guid(v)))); principalsAlternateId.SetCurrentValueComparer(new EntryCurrentValueComparer(principalsAlternateId)); - var discriminator = runtimeEntityType.AddProperty( - "Discriminator", + var type = runtimeEntityType.AddProperty( + "$type", typeof(string), propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(), afterSaveBehavior: PropertySaveBehavior.Throw, valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); - discriminator.SetGetter( - string (Dictionary entity) => ((((IDictionary)entity).ContainsKey("Discriminator") ? entity["Discriminator"] : null) == null ? null : ((string)((((IDictionary)entity).ContainsKey("Discriminator") ? entity["Discriminator"] : null)))), - bool (Dictionary entity) => (((IDictionary)entity).ContainsKey("Discriminator") ? entity["Discriminator"] : null) == null, - string (Dictionary instance) => ((((IDictionary)instance).ContainsKey("Discriminator") ? instance["Discriminator"] : null) == null ? null : ((string)((((IDictionary)instance).ContainsKey("Discriminator") ? instance["Discriminator"] : null)))), - bool (Dictionary instance) => (((IDictionary)instance).ContainsKey("Discriminator") ? instance["Discriminator"] : null) == null); - discriminator.SetSetter( - (Dictionary entity, string value) => entity["Discriminator"] = ((object)(value))); - discriminator.SetMaterializationSetter( - (Dictionary entity, string value) => entity["Discriminator"] = ((object)(value))); - discriminator.SetAccessors( - string (InternalEntityEntry entry) => ((string)((((IDictionary)((Dictionary)(entry.Entity))).ContainsKey("Discriminator") ? ((Dictionary)(entry.Entity))["Discriminator"] : null))), - string (InternalEntityEntry entry) => ((string)((((IDictionary)((Dictionary)(entry.Entity))).ContainsKey("Discriminator") ? ((Dictionary)(entry.Entity))["Discriminator"] : null))), - string (InternalEntityEntry entry) => entry.ReadOriginalValue(discriminator, 4), - string (InternalEntityEntry entry) => entry.GetCurrentValue(discriminator), + type.SetGetter( + string (Dictionary entity) => ((((IDictionary)entity).ContainsKey("$type") ? entity["$type"] : null) == null ? null : ((string)((((IDictionary)entity).ContainsKey("$type") ? entity["$type"] : null)))), + bool (Dictionary entity) => (((IDictionary)entity).ContainsKey("$type") ? entity["$type"] : null) == null, + string (Dictionary instance) => ((((IDictionary)instance).ContainsKey("$type") ? instance["$type"] : null) == null ? null : ((string)((((IDictionary)instance).ContainsKey("$type") ? instance["$type"] : null)))), + bool (Dictionary instance) => (((IDictionary)instance).ContainsKey("$type") ? instance["$type"] : null) == null); + type.SetSetter( + (Dictionary entity, string value) => entity["$type"] = ((object)(value))); + type.SetMaterializationSetter( + (Dictionary entity, string value) => entity["$type"] = ((object)(value))); + type.SetAccessors( + string (InternalEntityEntry entry) => ((string)((((IDictionary)((Dictionary)(entry.Entity))).ContainsKey("$type") ? ((Dictionary)(entry.Entity))["$type"] : null))), + string (InternalEntityEntry entry) => ((string)((((IDictionary)((Dictionary)(entry.Entity))).ContainsKey("$type") ? ((Dictionary)(entry.Entity))["$type"] : null))), + string (InternalEntityEntry entry) => entry.ReadOriginalValue(type, 4), + string (InternalEntityEntry entry) => entry.GetCurrentValue(type), object (ValueBuffer valueBuffer) => valueBuffer[4]); - discriminator.SetPropertyIndexes( + type.SetPropertyIndexes( index: 4, originalValueIndex: 4, shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); - discriminator.TypeMapping = CosmosTypeMapping.Default.Clone( + type.TypeMapping = CosmosTypeMapping.Default.Clone( comparer: new ValueComparer( bool (string v1, string v2) => v1 == v2, int (string v) => ((object)v).GetHashCode(), @@ -536,7 +536,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) var derivedsAlternateId = runtimeEntityType.FindProperty("DerivedsAlternateId")!; var principalsId = runtimeEntityType.FindProperty("PrincipalsId")!; var principalsAlternateId = runtimeEntityType.FindProperty("PrincipalsAlternateId")!; - var discriminator = runtimeEntityType.FindProperty("Discriminator")!; + var type = runtimeEntityType.FindProperty("$type")!; var __id = runtimeEntityType.FindProperty("__id")!; var __jObject = runtimeEntityType.FindProperty("__jObject")!; var rowid = runtimeEntityType.FindProperty("rowid")!; @@ -547,7 +547,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) ISnapshot (InternalEntityEntry source) => { var entity5 = ((Dictionary)(source.Entity)); - return ((ISnapshot)(new Snapshot(((ValueComparer)(((IProperty)derivedsId).GetValueComparer())).Snapshot(source.GetCurrentValue(derivedsId)), ((ValueComparer)(((IProperty)derivedsAlternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(derivedsAlternateId)), ((ValueComparer)(((IProperty)principalsId).GetValueComparer())).Snapshot(source.GetCurrentValue(principalsId)), ((ValueComparer)(((IProperty)principalsAlternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(principalsAlternateId)), (source.GetCurrentValue(discriminator) == null ? null : ((ValueComparer)(((IProperty)discriminator).GetValueComparer())).Snapshot(source.GetCurrentValue(discriminator))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject))), (source.GetCurrentValue(rowid) == null ? null : ((ValueComparer)(((IProperty)rowid).GetValueComparer())).Snapshot(source.GetCurrentValue(rowid)))))); + return ((ISnapshot)(new Snapshot(((ValueComparer)(((IProperty)derivedsId).GetValueComparer())).Snapshot(source.GetCurrentValue(derivedsId)), ((ValueComparer)(((IProperty)derivedsAlternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(derivedsAlternateId)), ((ValueComparer)(((IProperty)principalsId).GetValueComparer())).Snapshot(source.GetCurrentValue(principalsId)), ((ValueComparer)(((IProperty)principalsAlternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(principalsAlternateId)), (source.GetCurrentValue(type) == null ? null : ((ValueComparer)(((IProperty)type).GetValueComparer())).Snapshot(source.GetCurrentValue(type))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject))), (source.GetCurrentValue(rowid) == null ? null : ((ValueComparer)(((IProperty)rowid).GetValueComparer())).Snapshot(source.GetCurrentValue(rowid)))))); }); runtimeEntityType.SetStoreGeneratedValuesFactory( ISnapshot () => ((ISnapshot)(new Snapshot(((ValueComparer)(((IProperty)derivedsId).GetValueComparer())).Snapshot(default(long)), ((ValueComparer)(((IProperty)derivedsAlternateId).GetValueComparer())).Snapshot(default(Guid)), ((ValueComparer)(((IProperty)principalsId).GetValueComparer())).Snapshot(default(long)), ((ValueComparer)(((IProperty)principalsAlternateId).GetValueComparer())).Snapshot(default(Guid)), (default(JObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(default(JObject))))))); diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalDerivedEntityType.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalDerivedEntityType.cs index 1bb420dbf9b..e832cd63fa2 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalDerivedEntityType.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/PrincipalDerivedEntityType.cs @@ -24,7 +24,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas "Microsoft.EntityFrameworkCore.Scaffolding.CompiledModelTestBase+PrincipalDerived>", typeof(CompiledModelTestBase.PrincipalDerived>), baseEntityType, - discriminatorProperty: "Discriminator", + discriminatorProperty: "$type", discriminatorValue: "PrincipalDerived", propertyCount: 0, navigationCount: 2, @@ -89,7 +89,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { var id = runtimeEntityType.FindProperty("Id")!; var alternateId = runtimeEntityType.FindProperty("AlternateId")!; - var discriminator = runtimeEntityType.FindProperty("Discriminator")!; + var type = runtimeEntityType.FindProperty("$type")!; var enum1 = runtimeEntityType.FindProperty("Enum1")!; var enum2 = runtimeEntityType.FindProperty("Enum2")!; var flagsEnum1 = runtimeEntityType.FindProperty("FlagsEnum1")!; @@ -109,14 +109,14 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) ISnapshot (InternalEntityEntry source) => { var entity5 = ((CompiledModelTestBase.PrincipalDerived>)(source.Entity)); - return ((ISnapshot)(new Snapshot, IList, DateTime[], IEnumerable, IList, List, string, JObject>((source.GetCurrentValue(id) == null ? null : ((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id))), ((ValueComparer)(((IProperty)alternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(alternateId)), (source.GetCurrentValue(discriminator) == null ? null : ((ValueComparer)(((IProperty)discriminator).GetValueComparer())).Snapshot(source.GetCurrentValue(discriminator))), ((ValueComparer)(((IProperty)enum1).GetValueComparer())).Snapshot(source.GetCurrentValue(enum1)), (source.GetCurrentValue(enum2) == null ? null : ((ValueComparer)(((IProperty)enum2).GetValueComparer())).Snapshot(source.GetCurrentValue(enum2))), ((ValueComparer)(((IProperty)flagsEnum1).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum1)), ((ValueComparer)(((IProperty)flagsEnum2).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum2)), (((object)(source.GetCurrentValue>(refTypeEnumerable))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable))))))), (((object)(source.GetCurrentValue>(refTypeIList))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray))))))), (source.GetCurrentValue>(valueTypeEnumerable) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList))))))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject)))))); + return ((ISnapshot)(new Snapshot, IList, DateTime[], IEnumerable, IList, List, string, JObject>((source.GetCurrentValue(id) == null ? null : ((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id))), ((ValueComparer)(((IProperty)alternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(alternateId)), (source.GetCurrentValue(type) == null ? null : ((ValueComparer)(((IProperty)type).GetValueComparer())).Snapshot(source.GetCurrentValue(type))), ((ValueComparer)(((IProperty)enum1).GetValueComparer())).Snapshot(source.GetCurrentValue(enum1)), (source.GetCurrentValue(enum2) == null ? null : ((ValueComparer)(((IProperty)enum2).GetValueComparer())).Snapshot(source.GetCurrentValue(enum2))), ((ValueComparer)(((IProperty)flagsEnum1).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum1)), ((ValueComparer)(((IProperty)flagsEnum2).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum2)), (((object)(source.GetCurrentValue>(refTypeEnumerable))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable))))))), (((object)(source.GetCurrentValue>(refTypeIList))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray))))))), (source.GetCurrentValue>(valueTypeEnumerable) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList))))))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject)))))); }); runtimeEntityType.SetStoreGeneratedValuesFactory( ISnapshot () => Snapshot.Empty); runtimeEntityType.SetTemporaryValuesFactory( ISnapshot (InternalEntityEntry source) => Snapshot.Empty); runtimeEntityType.SetShadowValuesFactory( - ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("Discriminator") ? ((string)(source["Discriminator"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); + ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("$type") ? ((string)(source["$type"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); runtimeEntityType.SetEmptyShadowValuesFactory( ISnapshot () => ((ISnapshot)(new Snapshot(default(string), default(string), default(JObject))))); runtimeEntityType.SetRelationshipSnapshotFactory( diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalBaseEntityType.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalBaseEntityType.cs index 8fc41b9b8c8..7e549c3bd30 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalBaseEntityType.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalBaseEntityType.cs @@ -33,7 +33,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas "Microsoft.EntityFrameworkCore.Scaffolding.CompiledModelTestBase+PrincipalBase", typeof(CompiledModelTestBase.PrincipalBase), baseEntityType, - discriminatorProperty: "Discriminator", + discriminatorProperty: "$type", discriminatorValue: "PrincipalBase", derivedTypesCount: 1, propertyCount: 15, @@ -88,24 +88,24 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas id.SetKeyValueComparer(new NullableValueComparer(id.TypeMapping.KeyComparer)); id.SetCurrentValueComparer(new EntryCurrentValueComparer(id)); - var discriminator = runtimeEntityType.AddProperty( - "Discriminator", + var type = runtimeEntityType.AddProperty( + "$type", typeof(string), afterSaveBehavior: PropertySaveBehavior.Throw, valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); - discriminator.SetAccessors( + type.SetAccessors( string (InternalEntityEntry entry) => entry.ReadShadowValue(0), string (InternalEntityEntry entry) => entry.ReadShadowValue(0), - string (InternalEntityEntry entry) => entry.ReadOriginalValue(discriminator, 1), - string (InternalEntityEntry entry) => entry.GetCurrentValue(discriminator), + string (InternalEntityEntry entry) => entry.ReadOriginalValue(type, 1), + string (InternalEntityEntry entry) => entry.GetCurrentValue(type), object (ValueBuffer valueBuffer) => valueBuffer[1]); - discriminator.SetPropertyIndexes( + type.SetPropertyIndexes( index: 1, originalValueIndex: 1, shadowIndex: 0, relationshipIndex: -1, storeGenerationIndex: -1); - discriminator.TypeMapping = CosmosTypeMapping.Default.Clone( + type.TypeMapping = CosmosTypeMapping.Default.Clone( comparer: new ValueComparer( bool (string v1, string v2) => v1 == v2, int (string v) => ((object)v).GetHashCode(), @@ -2194,7 +2194,7 @@ public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEnt public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { var id = runtimeEntityType.FindProperty("Id")!; - var discriminator = runtimeEntityType.FindProperty("Discriminator")!; + var type = runtimeEntityType.FindProperty("$type")!; var enum1 = runtimeEntityType.FindProperty("Enum1")!; var enum2 = runtimeEntityType.FindProperty("Enum2")!; var flagsEnum1 = runtimeEntityType.FindProperty("FlagsEnum1")!; @@ -2240,7 +2240,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) ISnapshot (InternalEntityEntry source) => { var entity = ((CompiledModelTestBase.PrincipalBase)(source.Entity)); - var liftedArg = ((ISnapshot)(new Snapshot, IList, DateTime[], IEnumerable, IList, List, string, JObject, string, int, IEnumerable, IList, DateTime[], IEnumerable, IList, List, Guid, CompiledModelTestBase.AnEnum, CompiledModelTestBase.AnEnum?, CompiledModelTestBase.AFlagsEnum, CompiledModelTestBase.AFlagsEnum, long?, IEnumerable>((source.GetCurrentValue(id) == null ? null : ((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id))), (source.GetCurrentValue(discriminator) == null ? null : ((ValueComparer)(((IProperty)discriminator).GetValueComparer())).Snapshot(source.GetCurrentValue(discriminator))), ((ValueComparer)(((IProperty)enum1).GetValueComparer())).Snapshot(source.GetCurrentValue(enum1)), (source.GetCurrentValue(enum2) == null ? null : ((ValueComparer)(((IProperty)enum2).GetValueComparer())).Snapshot(source.GetCurrentValue(enum2))), ((ValueComparer)(((IProperty)flagsEnum1).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum1)), ((ValueComparer)(((IProperty)flagsEnum2).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum2)), (source.GetCurrentValue(principalBaseId) == null ? null : ((ValueComparer)(((IProperty)principalBaseId).GetValueComparer())).Snapshot(source.GetCurrentValue(principalBaseId))), (((object)(source.GetCurrentValue>(refTypeEnumerable))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable))))))), (((object)(source.GetCurrentValue>(refTypeIList))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray))))))), (source.GetCurrentValue>(valueTypeEnumerable) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList))))))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject))), (source.GetCurrentValue(details) == null ? null : ((ValueComparer)(((IProperty)details).GetValueComparer())).Snapshot(source.GetCurrentValue(details))), ((ValueComparer)(((IProperty)number).GetValueComparer())).Snapshot(source.GetCurrentValue(number)), (((object)(source.GetCurrentValue>(refTypeEnumerable0))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable0).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable0))))))), (((object)(source.GetCurrentValue>(refTypeIList0))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList0).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList0))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray0))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray0))))))), (source.GetCurrentValue>(valueTypeEnumerable0) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable0).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable0))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList0))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList0))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList0))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList0))))))), ((ValueComparer)(((IProperty)alternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(alternateId)), ((ValueComparer)(((IProperty)enum10).GetValueComparer())).Snapshot(source.GetCurrentValue(enum10)), (source.GetCurrentValue(enum20) == null ? null : ((ValueComparer)(((IProperty)enum20).GetValueComparer())).Snapshot(source.GetCurrentValue(enum20))), ((ValueComparer)(((IProperty)flagsEnum10).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum10)), ((ValueComparer)(((IProperty)flagsEnum20).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum20)), (source.GetCurrentValue(id0) == null ? null : ((ValueComparer)(((IProperty)id0).GetValueComparer())).Snapshot(source.GetCurrentValue(id0))), (((object)(source.GetCurrentValue>(refTypeEnumerable1))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable1).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable1)))))))))); + var liftedArg = ((ISnapshot)(new Snapshot, IList, DateTime[], IEnumerable, IList, List, string, JObject, string, int, IEnumerable, IList, DateTime[], IEnumerable, IList, List, Guid, CompiledModelTestBase.AnEnum, CompiledModelTestBase.AnEnum?, CompiledModelTestBase.AFlagsEnum, CompiledModelTestBase.AFlagsEnum, long?, IEnumerable>((source.GetCurrentValue(id) == null ? null : ((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id))), (source.GetCurrentValue(type) == null ? null : ((ValueComparer)(((IProperty)type).GetValueComparer())).Snapshot(source.GetCurrentValue(type))), ((ValueComparer)(((IProperty)enum1).GetValueComparer())).Snapshot(source.GetCurrentValue(enum1)), (source.GetCurrentValue(enum2) == null ? null : ((ValueComparer)(((IProperty)enum2).GetValueComparer())).Snapshot(source.GetCurrentValue(enum2))), ((ValueComparer)(((IProperty)flagsEnum1).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum1)), ((ValueComparer)(((IProperty)flagsEnum2).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum2)), (source.GetCurrentValue(principalBaseId) == null ? null : ((ValueComparer)(((IProperty)principalBaseId).GetValueComparer())).Snapshot(source.GetCurrentValue(principalBaseId))), (((object)(source.GetCurrentValue>(refTypeEnumerable))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable))))))), (((object)(source.GetCurrentValue>(refTypeIList))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray))))))), (source.GetCurrentValue>(valueTypeEnumerable) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList))))))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject))), (source.GetCurrentValue(details) == null ? null : ((ValueComparer)(((IProperty)details).GetValueComparer())).Snapshot(source.GetCurrentValue(details))), ((ValueComparer)(((IProperty)number).GetValueComparer())).Snapshot(source.GetCurrentValue(number)), (((object)(source.GetCurrentValue>(refTypeEnumerable0))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable0).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable0))))))), (((object)(source.GetCurrentValue>(refTypeIList0))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList0).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList0))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray0))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray0))))))), (source.GetCurrentValue>(valueTypeEnumerable0) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable0).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable0))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList0))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList0))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList0))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList0))))))), ((ValueComparer)(((IProperty)alternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(alternateId)), ((ValueComparer)(((IProperty)enum10).GetValueComparer())).Snapshot(source.GetCurrentValue(enum10)), (source.GetCurrentValue(enum20) == null ? null : ((ValueComparer)(((IProperty)enum20).GetValueComparer())).Snapshot(source.GetCurrentValue(enum20))), ((ValueComparer)(((IProperty)flagsEnum10).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum10)), ((ValueComparer)(((IProperty)flagsEnum20).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum20)), (source.GetCurrentValue(id0) == null ? null : ((ValueComparer)(((IProperty)id0).GetValueComparer())).Snapshot(source.GetCurrentValue(id0))), (((object)(source.GetCurrentValue>(refTypeEnumerable1))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable1).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable1)))))))))); var entity0 = ((CompiledModelTestBase.PrincipalBase)(source.Entity)); return ((ISnapshot)(new MultiSnapshot(new ISnapshot[] { liftedArg, ((ISnapshot)(new Snapshot, DateTime[], IEnumerable, IList, List>((((object)(source.GetCurrentValue>(refTypeIList1))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList1).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList1))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray1))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray1).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray1))))))), (source.GetCurrentValue>(valueTypeEnumerable1) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable1).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable1))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList1))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList1).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList1))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList1))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList1).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList1)))))))))) }))); }); @@ -2249,7 +2249,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) runtimeEntityType.SetTemporaryValuesFactory( ISnapshot (InternalEntityEntry source) => ((ISnapshot)(new Snapshot(default(long? ))))); runtimeEntityType.SetShadowValuesFactory( - ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("Discriminator") ? ((string)(source["Discriminator"])) : null), (source.ContainsKey("PrincipalBaseId") ? ((long? )(source["PrincipalBaseId"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); + ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("$type") ? ((string)(source["$type"])) : null), (source.ContainsKey("PrincipalBaseId") ? ((long? )(source["PrincipalBaseId"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); runtimeEntityType.SetEmptyShadowValuesFactory( ISnapshot () => ((ISnapshot)(new Snapshot(default(string), default(long? ), default(string), default(JObject))))); runtimeEntityType.SetRelationshipSnapshotFactory( diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalDerivedEntityType.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalDerivedEntityType.cs index 6cba7c7ce96..56d2e799fe1 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalDerivedEntityType.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalDerivedEntityType.cs @@ -24,7 +24,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas "Microsoft.EntityFrameworkCore.Scaffolding.CompiledModelTestBase+PrincipalDerived>", typeof(CompiledModelTestBase.PrincipalDerived>), baseEntityType, - discriminatorProperty: "Discriminator", + discriminatorProperty: "$type", discriminatorValue: "PrincipalDerived", propertyCount: 0); @@ -34,7 +34,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { var id = runtimeEntityType.FindProperty("Id")!; - var discriminator = runtimeEntityType.FindProperty("Discriminator")!; + var type = runtimeEntityType.FindProperty("$type")!; var enum1 = runtimeEntityType.FindProperty("Enum1")!; var enum2 = runtimeEntityType.FindProperty("Enum2")!; var flagsEnum1 = runtimeEntityType.FindProperty("FlagsEnum1")!; @@ -77,7 +77,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) ISnapshot (InternalEntityEntry source) => { var entity1 = ((CompiledModelTestBase.PrincipalDerived>)(source.Entity)); - var liftedArg0 = ((ISnapshot)(new Snapshot, IList, DateTime[], IEnumerable, IList, List, string, JObject, string, int, IEnumerable, IList, DateTime[], IEnumerable, IList, List, Guid, CompiledModelTestBase.AnEnum, CompiledModelTestBase.AnEnum?, CompiledModelTestBase.AFlagsEnum, CompiledModelTestBase.AFlagsEnum, long?, IEnumerable>((source.GetCurrentValue(id) == null ? null : ((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id))), (source.GetCurrentValue(discriminator) == null ? null : ((ValueComparer)(((IProperty)discriminator).GetValueComparer())).Snapshot(source.GetCurrentValue(discriminator))), ((ValueComparer)(((IProperty)enum1).GetValueComparer())).Snapshot(source.GetCurrentValue(enum1)), (source.GetCurrentValue(enum2) == null ? null : ((ValueComparer)(((IProperty)enum2).GetValueComparer())).Snapshot(source.GetCurrentValue(enum2))), ((ValueComparer)(((IProperty)flagsEnum1).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum1)), ((ValueComparer)(((IProperty)flagsEnum2).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum2)), (source.GetCurrentValue(principalBaseId) == null ? null : ((ValueComparer)(((IProperty)principalBaseId).GetValueComparer())).Snapshot(source.GetCurrentValue(principalBaseId))), (((object)(source.GetCurrentValue>(refTypeEnumerable))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable))))))), (((object)(source.GetCurrentValue>(refTypeIList))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray))))))), (source.GetCurrentValue>(valueTypeEnumerable) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList))))))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject))), (source.GetCurrentValue(details) == null ? null : ((ValueComparer)(((IProperty)details).GetValueComparer())).Snapshot(source.GetCurrentValue(details))), ((ValueComparer)(((IProperty)number).GetValueComparer())).Snapshot(source.GetCurrentValue(number)), (((object)(source.GetCurrentValue>(refTypeEnumerable0))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable0).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable0))))))), (((object)(source.GetCurrentValue>(refTypeIList0))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList0).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList0))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray0))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray0))))))), (source.GetCurrentValue>(valueTypeEnumerable0) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable0).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable0))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList0))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList0))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList0))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList0))))))), ((ValueComparer)(((IProperty)alternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(alternateId)), ((ValueComparer)(((IProperty)enum10).GetValueComparer())).Snapshot(source.GetCurrentValue(enum10)), (source.GetCurrentValue(enum20) == null ? null : ((ValueComparer)(((IProperty)enum20).GetValueComparer())).Snapshot(source.GetCurrentValue(enum20))), ((ValueComparer)(((IProperty)flagsEnum10).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum10)), ((ValueComparer)(((IProperty)flagsEnum20).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum20)), (source.GetCurrentValue(id0) == null ? null : ((ValueComparer)(((IProperty)id0).GetValueComparer())).Snapshot(source.GetCurrentValue(id0))), (((object)(source.GetCurrentValue>(refTypeEnumerable1))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable1).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable1)))))))))); + var liftedArg0 = ((ISnapshot)(new Snapshot, IList, DateTime[], IEnumerable, IList, List, string, JObject, string, int, IEnumerable, IList, DateTime[], IEnumerable, IList, List, Guid, CompiledModelTestBase.AnEnum, CompiledModelTestBase.AnEnum?, CompiledModelTestBase.AFlagsEnum, CompiledModelTestBase.AFlagsEnum, long?, IEnumerable>((source.GetCurrentValue(id) == null ? null : ((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id))), (source.GetCurrentValue(type) == null ? null : ((ValueComparer)(((IProperty)type).GetValueComparer())).Snapshot(source.GetCurrentValue(type))), ((ValueComparer)(((IProperty)enum1).GetValueComparer())).Snapshot(source.GetCurrentValue(enum1)), (source.GetCurrentValue(enum2) == null ? null : ((ValueComparer)(((IProperty)enum2).GetValueComparer())).Snapshot(source.GetCurrentValue(enum2))), ((ValueComparer)(((IProperty)flagsEnum1).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum1)), ((ValueComparer)(((IProperty)flagsEnum2).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum2)), (source.GetCurrentValue(principalBaseId) == null ? null : ((ValueComparer)(((IProperty)principalBaseId).GetValueComparer())).Snapshot(source.GetCurrentValue(principalBaseId))), (((object)(source.GetCurrentValue>(refTypeEnumerable))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable))))))), (((object)(source.GetCurrentValue>(refTypeIList))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray))))))), (source.GetCurrentValue>(valueTypeEnumerable) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList))))))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject))), (source.GetCurrentValue(details) == null ? null : ((ValueComparer)(((IProperty)details).GetValueComparer())).Snapshot(source.GetCurrentValue(details))), ((ValueComparer)(((IProperty)number).GetValueComparer())).Snapshot(source.GetCurrentValue(number)), (((object)(source.GetCurrentValue>(refTypeEnumerable0))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable0).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable0))))))), (((object)(source.GetCurrentValue>(refTypeIList0))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList0).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList0))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray0))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray0))))))), (source.GetCurrentValue>(valueTypeEnumerable0) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable0).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable0))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList0))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList0))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList0))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList0).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList0))))))), ((ValueComparer)(((IProperty)alternateId).GetValueComparer())).Snapshot(source.GetCurrentValue(alternateId)), ((ValueComparer)(((IProperty)enum10).GetValueComparer())).Snapshot(source.GetCurrentValue(enum10)), (source.GetCurrentValue(enum20) == null ? null : ((ValueComparer)(((IProperty)enum20).GetValueComparer())).Snapshot(source.GetCurrentValue(enum20))), ((ValueComparer)(((IProperty)flagsEnum10).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum10)), ((ValueComparer)(((IProperty)flagsEnum20).GetValueComparer())).Snapshot(source.GetCurrentValue(flagsEnum20)), (source.GetCurrentValue(id0) == null ? null : ((ValueComparer)(((IProperty)id0).GetValueComparer())).Snapshot(source.GetCurrentValue(id0))), (((object)(source.GetCurrentValue>(refTypeEnumerable1))) == null ? null : ((IEnumerable)(((ValueComparer)(((IProperty)refTypeEnumerable1).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeEnumerable1)))))))))); var entity2 = ((CompiledModelTestBase.PrincipalDerived>)(source.Entity)); return ((ISnapshot)(new MultiSnapshot(new ISnapshot[] { liftedArg0, ((ISnapshot)(new Snapshot, DateTime[], IEnumerable, IList, List>((((object)(source.GetCurrentValue>(refTypeIList1))) == null ? null : ((IList)(((ValueComparer)(((IProperty)refTypeIList1).GetValueComparer())).Snapshot(((object)(source.GetCurrentValue>(refTypeIList1))))))), (((IEnumerable)(source.GetCurrentValue(valueTypeArray1))) == null ? null : ((DateTime[])(((ValueComparer>)(((IProperty)valueTypeArray1).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue(valueTypeArray1))))))), (source.GetCurrentValue>(valueTypeEnumerable1) == null ? null : ((ValueComparer>)(((IProperty)valueTypeEnumerable1).GetValueComparer())).Snapshot(source.GetCurrentValue>(valueTypeEnumerable1))), (((IEnumerable)(source.GetCurrentValue>(valueTypeIList1))) == null ? null : ((IList)(((ValueComparer>)(((IProperty)valueTypeIList1).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeIList1))))))), (((IEnumerable)(source.GetCurrentValue>(valueTypeList1))) == null ? null : ((List)(((ValueComparer>)(((IProperty)valueTypeList1).GetValueComparer())).Snapshot(((IEnumerable)(source.GetCurrentValue>(valueTypeList1)))))))))) }))); }); @@ -86,7 +86,7 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) runtimeEntityType.SetTemporaryValuesFactory( ISnapshot (InternalEntityEntry source) => ((ISnapshot)(new Snapshot(default(long? ))))); runtimeEntityType.SetShadowValuesFactory( - ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("Discriminator") ? ((string)(source["Discriminator"])) : null), (source.ContainsKey("PrincipalBaseId") ? ((long? )(source["PrincipalBaseId"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); + ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("$type") ? ((string)(source["$type"])) : null), (source.ContainsKey("PrincipalBaseId") ? ((long? )(source["PrincipalBaseId"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); runtimeEntityType.SetEmptyShadowValuesFactory( ISnapshot () => ((ISnapshot)(new Snapshot(default(string), default(long? ), default(string), default(JObject))))); runtimeEntityType.SetRelationshipSnapshotFactory( diff --git a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DependentDerivedEntityType.cs b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DependentDerivedEntityType.cs index aaeeeedef92..0ff9299efb3 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DependentDerivedEntityType.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/SimpleModel/DependentDerivedEntityType.cs @@ -29,7 +29,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas "Microsoft.EntityFrameworkCore.Scaffolding.CompiledModelTestBase+DependentDerived", typeof(CompiledModelTestBase.DependentDerived), baseEntityType, - discriminatorProperty: "Discriminator", + discriminatorProperty: "$type", discriminatorValue: "DependentDerived", propertyCount: 5, keyCount: 1); @@ -79,34 +79,24 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas jsonValueReaderWriter: JsonInt32ReaderWriter.Instance); id.SetCurrentValueComparer(new EntryCurrentValueComparer(id)); - var data = runtimeEntityType.AddProperty( - "Data", + var type = runtimeEntityType.AddProperty( + "$type", typeof(string), - propertyInfo: typeof(CompiledModelTestBase.DependentDerived).GetProperty("Data", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(CompiledModelTestBase.DependentDerived).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - nullable: true); - data.SetGetter( - string (CompiledModelTestBase.DependentDerived entity) => DependentDerivedUnsafeAccessors.Data(entity), - bool (CompiledModelTestBase.DependentDerived entity) => DependentDerivedUnsafeAccessors.Data(entity) == null, - string (CompiledModelTestBase.DependentDerived instance) => DependentDerivedUnsafeAccessors.Data(instance), - bool (CompiledModelTestBase.DependentDerived instance) => DependentDerivedUnsafeAccessors.Data(instance) == null); - data.SetSetter( - (CompiledModelTestBase.DependentDerived entity, string value) => DependentDerivedUnsafeAccessors.Data(entity) = value); - data.SetMaterializationSetter( - (CompiledModelTestBase.DependentDerived entity, string value) => DependentDerivedUnsafeAccessors.Data(entity) = value); - data.SetAccessors( - string (InternalEntityEntry entry) => DependentDerivedUnsafeAccessors.Data(((CompiledModelTestBase.DependentDerived)(entry.Entity))), - string (InternalEntityEntry entry) => DependentDerivedUnsafeAccessors.Data(((CompiledModelTestBase.DependentDerived)(entry.Entity))), - string (InternalEntityEntry entry) => entry.ReadOriginalValue(data, 1), - string (InternalEntityEntry entry) => entry.GetCurrentValue(data), + afterSaveBehavior: PropertySaveBehavior.Throw, + valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); + type.SetAccessors( + string (InternalEntityEntry entry) => entry.ReadShadowValue(0), + string (InternalEntityEntry entry) => entry.ReadShadowValue(0), + string (InternalEntityEntry entry) => entry.ReadOriginalValue(type, 1), + string (InternalEntityEntry entry) => entry.GetCurrentValue(type), object (ValueBuffer valueBuffer) => valueBuffer[1]); - data.SetPropertyIndexes( + type.SetPropertyIndexes( index: 1, originalValueIndex: 1, - shadowIndex: -1, + shadowIndex: 0, relationshipIndex: -1, storeGenerationIndex: -1); - data.TypeMapping = CosmosTypeMapping.Default.Clone( + type.TypeMapping = CosmosTypeMapping.Default.Clone( comparer: new ValueComparer( bool (string v1, string v2) => v1 == v2, int (string v) => ((object)v).GetHashCode(), @@ -122,24 +112,34 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas clrType: typeof(string), jsonValueReaderWriter: JsonStringReaderWriter.Instance); - var discriminator = runtimeEntityType.AddProperty( - "Discriminator", + var data = runtimeEntityType.AddProperty( + "Data", typeof(string), - afterSaveBehavior: PropertySaveBehavior.Throw, - valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create); - discriminator.SetAccessors( - string (InternalEntityEntry entry) => entry.ReadShadowValue(0), - string (InternalEntityEntry entry) => entry.ReadShadowValue(0), - string (InternalEntityEntry entry) => entry.ReadOriginalValue(discriminator, 2), - string (InternalEntityEntry entry) => entry.GetCurrentValue(discriminator), + propertyInfo: typeof(CompiledModelTestBase.DependentDerived).GetProperty("Data", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(CompiledModelTestBase.DependentDerived).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true); + data.SetGetter( + string (CompiledModelTestBase.DependentDerived entity) => DependentDerivedUnsafeAccessors.Data(entity), + bool (CompiledModelTestBase.DependentDerived entity) => DependentDerivedUnsafeAccessors.Data(entity) == null, + string (CompiledModelTestBase.DependentDerived instance) => DependentDerivedUnsafeAccessors.Data(instance), + bool (CompiledModelTestBase.DependentDerived instance) => DependentDerivedUnsafeAccessors.Data(instance) == null); + data.SetSetter( + (CompiledModelTestBase.DependentDerived entity, string value) => DependentDerivedUnsafeAccessors.Data(entity) = value); + data.SetMaterializationSetter( + (CompiledModelTestBase.DependentDerived entity, string value) => DependentDerivedUnsafeAccessors.Data(entity) = value); + data.SetAccessors( + string (InternalEntityEntry entry) => DependentDerivedUnsafeAccessors.Data(((CompiledModelTestBase.DependentDerived)(entry.Entity))), + string (InternalEntityEntry entry) => DependentDerivedUnsafeAccessors.Data(((CompiledModelTestBase.DependentDerived)(entry.Entity))), + string (InternalEntityEntry entry) => entry.ReadOriginalValue(data, 2), + string (InternalEntityEntry entry) => entry.GetCurrentValue(data), object (ValueBuffer valueBuffer) => valueBuffer[2]); - discriminator.SetPropertyIndexes( + data.SetPropertyIndexes( index: 2, originalValueIndex: 2, - shadowIndex: 0, + shadowIndex: -1, relationshipIndex: -1, storeGenerationIndex: -1); - discriminator.TypeMapping = CosmosTypeMapping.Default.Clone( + data.TypeMapping = CosmosTypeMapping.Default.Clone( comparer: new ValueComparer( bool (string v1, string v2) => v1 == v2, int (string v) => ((object)v).GetHashCode(), @@ -234,8 +234,8 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) { var id = runtimeEntityType.FindProperty("Id")!; + var type = runtimeEntityType.FindProperty("$type")!; var data = runtimeEntityType.FindProperty("Data")!; - var discriminator = runtimeEntityType.FindProperty("Discriminator")!; var __id = runtimeEntityType.FindProperty("__id")!; var __jObject = runtimeEntityType.FindProperty("__jObject")!; var key = runtimeEntityType.FindKey(new[] { id }); @@ -245,14 +245,14 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) ISnapshot (InternalEntityEntry source) => { var entity = ((CompiledModelTestBase.DependentDerived)(source.Entity)); - return ((ISnapshot)(new Snapshot(((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id)), (source.GetCurrentValue(data) == null ? null : ((ValueComparer)(((IProperty)data).GetValueComparer())).Snapshot(source.GetCurrentValue(data))), (source.GetCurrentValue(discriminator) == null ? null : ((ValueComparer)(((IProperty)discriminator).GetValueComparer())).Snapshot(source.GetCurrentValue(discriminator))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject)))))); + return ((ISnapshot)(new Snapshot(((ValueComparer)(((IProperty)id).GetValueComparer())).Snapshot(source.GetCurrentValue(id)), (source.GetCurrentValue(type) == null ? null : ((ValueComparer)(((IProperty)type).GetValueComparer())).Snapshot(source.GetCurrentValue(type))), (source.GetCurrentValue(data) == null ? null : ((ValueComparer)(((IProperty)data).GetValueComparer())).Snapshot(source.GetCurrentValue(data))), (source.GetCurrentValue(__id) == null ? null : ((ValueComparer)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue(__id))), (source.GetCurrentValue(__jObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue(__jObject)))))); }); runtimeEntityType.SetStoreGeneratedValuesFactory( ISnapshot () => ((ISnapshot)(new Snapshot((default(JObject) == null ? null : ((ValueComparer)(((IProperty)__jObject).GetValueComparer())).Snapshot(default(JObject))))))); runtimeEntityType.SetTemporaryValuesFactory( ISnapshot (InternalEntityEntry source) => ((ISnapshot)(new Snapshot(default(JObject))))); runtimeEntityType.SetShadowValuesFactory( - ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("Discriminator") ? ((string)(source["Discriminator"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); + ISnapshot (IDictionary source) => ((ISnapshot)(new Snapshot((source.ContainsKey("$type") ? ((string)(source["$type"])) : null), (source.ContainsKey("__id") ? ((string)(source["__id"])) : null), (source.ContainsKey("__jObject") ? ((JObject)(source["__jObject"])) : null))))); runtimeEntityType.SetEmptyShadowValuesFactory( ISnapshot () => ((ISnapshot)(new Snapshot(default(string), default(string), default(JObject))))); runtimeEntityType.SetRelationshipSnapshotFactory( diff --git a/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosModelAsserter.cs b/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosModelAsserter.cs index 39ebe9ee0e1..5c7830ae316 100644 --- a/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosModelAsserter.cs +++ b/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosModelAsserter.cs @@ -19,8 +19,8 @@ public override void AssertEqual( bool assertOrder = false, bool compareAnnotations = false) { - expectedProperties = expectedProperties.Where(p => p.Name != "__jObject" && p.Name != "__id" && p.Name != "Discriminator"); - actualProperties = actualProperties.Where(p => p.Name != "__jObject" && p.Name != "__id" && p.Name != "Discriminator"); + expectedProperties = expectedProperties.Where(p => p.Name != "__jObject" && p.Name != "__id" && p.Name != "$type"); + actualProperties = actualProperties.Where(p => p.Name != "__jObject" && p.Name != "__id" && p.Name != "$type"); base.AssertEqual(expectedProperties, actualProperties, assertOrder, compareAnnotations); } diff --git a/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosNorthwindTestStoreFactory.cs b/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosNorthwindTestStoreFactory.cs index d69469c15ac..d637630a0b3 100644 --- a/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosNorthwindTestStoreFactory.cs +++ b/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosNorthwindTestStoreFactory.cs @@ -5,7 +5,7 @@ namespace Microsoft.EntityFrameworkCore.TestUtilities; public class CosmosNorthwindTestStoreFactory : CosmosTestStoreFactory { - private const string Name = "Northwind2"; + private const string Name = "Northwind3"; public static new CosmosNorthwindTestStoreFactory Instance { get; } = new(); diff --git a/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs b/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs index fccdb53f71f..843686b55c6 100644 --- a/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs +++ b/test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs @@ -74,7 +74,7 @@ private CosmosTestStore( } private static string CreateName(string name) - => TestEnvironment.IsEmulator || name == "Northwind" || name == "Northwind2" + => TestEnvironment.IsEmulator || name == "Northwind" || name == "Northwind2" || name == "Northwind3" ? name : name + _runId; @@ -218,7 +218,7 @@ private async Task CreateFromFile(DbContext context) ? $"{entityName}|{document["id"]}" : $"{document["id"]}"; - document["Discriminator"] = entityName; + document["$type"] = entityName; await cosmosClient.CreateItemAsync( containerName!, document, new FakeUpdateEntry()).ConfigureAwait(false); @@ -663,6 +663,9 @@ public IIndex FindIndex(string name) public IIndex FindIndex(IReadOnlyList properties) => throw new NotImplementedException(); + public string GetEmbeddedDiscriminatorName() + => throw new NotImplementedException(); + public PropertyInfo FindIndexerPropertyInfo() => throw new NotImplementedException(); diff --git a/test/EFCore.Cosmos.Tests/Extensions/CosmosBuilderExtensionsTest.cs b/test/EFCore.Cosmos.Tests/Extensions/CosmosBuilderExtensionsTest.cs index 090a5088faa..8c10c4e3843 100644 --- a/test/EFCore.Cosmos.Tests/Extensions/CosmosBuilderExtensionsTest.cs +++ b/test/EFCore.Cosmos.Tests/Extensions/CosmosBuilderExtensionsTest.cs @@ -142,7 +142,7 @@ public void Default_discriminator_can_be_removed() var entityType = modelBuilder.Model.FindEntityType(typeof(Customer))!; - Assert.Equal("Discriminator", entityType.FindDiscriminatorProperty()!.Name); + Assert.Equal("$type", entityType.FindDiscriminatorProperty()!.Name); Assert.Equal(nameof(Customer), entityType.GetDiscriminatorValue()); modelBuilder.Entity().HasNoDiscriminator(); @@ -152,7 +152,7 @@ public void Default_discriminator_can_be_removed() modelBuilder.Entity().HasBaseType(); - Assert.Equal("Discriminator", entityType.FindDiscriminatorProperty()!.Name); + Assert.Equal("$type", entityType.FindDiscriminatorProperty()!.Name); Assert.Equal(nameof(Customer), entityType.GetDiscriminatorValue()); modelBuilder.Entity().HasBaseType((string)null); diff --git a/test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.cs b/test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.cs index 14cbb502477..91fd89830ed 100644 --- a/test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.cs +++ b/test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.cs @@ -132,6 +132,13 @@ public virtual TestModelBuilder UsePropertyAccessMode(PropertyAccessMode propert return this; } + public virtual TestModelBuilder HasEmbeddedDiscriminatorName(string name) + { + ModelBuilder.HasEmbeddedDiscriminatorName(name); + + return this; + } + ModelBuilder IInfrastructure.Instance => ModelBuilder; } diff --git a/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs b/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs index 1dd8956424f..d00ba6ec514 100644 --- a/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs +++ b/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs @@ -481,6 +481,7 @@ public void RemoveAllConventions() ConventionSet.KeyAnnotationChangedConventions.Clear(); ConventionSet.KeyRemovedConventions.Clear(); ConventionSet.ModelAnnotationChangedConventions.Clear(); + ConventionSet.ModelEmbeddedDiscriminatorNameConventions.Clear(); ConventionSet.ModelFinalizedConventions.Clear(); ConventionSet.ModelFinalizingConventions.Clear(); ConventionSet.ModelInitializedConventions.Clear(); From 4e276c320184922980be24d0c12ebb354bd7385f Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Mon, 5 Aug 2024 10:33:12 +0100 Subject: [PATCH 2/2] Review changes --- .../CosmosDiscriminatorConvention.cs | 7 +- ...odelEmbeddedDiscriminatorNameConvention.cs | 4 +- ...tionDispatcher.ImmediateConventionScope.cs | 4 +- .../Internal/ConventionDispatcher.cs | 2 +- .../Query/OwnedQueryCosmosTest.cs | 2 +- .../Conventions/ConventionDispatcherTest.cs | 88 +++++++++++++++++++ 6 files changed, 99 insertions(+), 8 deletions(-) diff --git a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs index d761853a232..ea91a2777fe 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs @@ -165,8 +165,11 @@ public override void ProcessEntityTypeRemoved( } /// - public void ProcessEmbeddedDiscriminatorName( - IConventionModelBuilder modelBuilder, string? oldName, string? newName, IConventionContext context) + public virtual void ProcessEmbeddedDiscriminatorName( + IConventionModelBuilder modelBuilder, + string? newName, + string? oldName, + IConventionContext context) { if (oldName == newName) { diff --git a/src/EFCore/Metadata/Conventions/IModelEmbeddedDiscriminatorNameConvention.cs b/src/EFCore/Metadata/Conventions/IModelEmbeddedDiscriminatorNameConvention.cs index 6b8c7b74228..6e8d03b1252 100644 --- a/src/EFCore/Metadata/Conventions/IModelEmbeddedDiscriminatorNameConvention.cs +++ b/src/EFCore/Metadata/Conventions/IModelEmbeddedDiscriminatorNameConvention.cs @@ -15,12 +15,12 @@ public interface IModelEmbeddedDiscriminatorNameConvention : IConvention /// Called after has been called. /// /// The builder for the model. - /// The current discriminator name. /// The new discriminator name. + /// The current discriminator name. /// Additional information associated with convention execution. void ProcessEmbeddedDiscriminatorName( IConventionModelBuilder modelBuilder, - string? oldName, string? newName, + string? oldName, IConventionContext context); } diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs index 45e87dc3890..2ccac2e18a5 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs @@ -150,13 +150,13 @@ public IConventionModelBuilder OnModelInitialized(IConventionModelBuilder modelB { using (_dispatcher.DelayConventions()) { - _stringConventionContext.ResetState(oldName); + _stringConventionContext.ResetState(newName); #if DEBUG var initialValue = modelBuilder.Metadata.GetEmbeddedDiscriminatorName(); #endif foreach (var modelConvention in _conventionSet.ModelEmbeddedDiscriminatorNameConventions) { - modelConvention.ProcessEmbeddedDiscriminatorName(modelBuilder, oldName, newName, _stringConventionContext); + modelConvention.ProcessEmbeddedDiscriminatorName(modelBuilder, newName, oldName, _stringConventionContext); if (_stringConventionContext.ShouldStopProcessing()) { diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs index e8881bc3def..a223d479e2c 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs @@ -70,7 +70,7 @@ public virtual IConventionModelBuilder OnModelFinalizing(IConventionModelBuilder { if (name == CoreAnnotationNames.EmbeddedDiscriminatorName) { - _scope.OnModelEmbeddedDiscriminatorNameChanged(modelBuilder, oldAnnotation?.Name, annotation?.Name); + _scope.OnModelEmbeddedDiscriminatorNameChanged(modelBuilder, (string?)oldAnnotation?.Value, (string?)annotation?.Value); return annotation; } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs index 169931115d1..b1563b49ce7 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs @@ -402,7 +402,7 @@ public override Task Project_owned_reference_navigation_which_does_not_own_addit """ SELECT VALUE c FROM root c -WHERE c["Discriminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") +WHERE c["Terminator"] IN ("OwnedPerson", "Branch", "LeafB", "LeafA") ORDER BY c["Id"] """); }); diff --git a/test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs b/test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs index 3ea047e33d0..352ed8d8e34 100644 --- a/test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs @@ -232,6 +232,94 @@ public void ProcessModelAnnotationChanged( } } + [InlineData(false, false)] + [InlineData(true, false)] + [InlineData(false, true)] + [InlineData(true, true)] + [ConditionalTheory] + public void ModelEmbeddedDiscriminatorName_calls_conventions_in_order(bool useBuilder, bool useScope) + { + var conventions = new ConventionSet(); + + var convention1 = new ModelEmbeddedDiscriminatorNameConvention(false); + var convention2 = new ModelEmbeddedDiscriminatorNameConvention(true); + var convention3 = new ModelEmbeddedDiscriminatorNameConvention(false); + conventions.Add(convention1); + conventions.Add(convention2); + conventions.Add(convention3); + + var builder = new InternalModelBuilder(new Model(conventions)); + + var scope = useScope ? builder.Metadata.ConventionDispatcher.DelayConventions() : null; + + if (useBuilder) + { + Assert.NotNull(builder.HasEmbeddedDiscriminatorName("Cheese", ConfigurationSource.Convention)); + } + else + { + builder.Metadata.SetEmbeddedDiscriminatorName("Cheese", ConfigurationSource.Convention); + } + + if (useScope) + { + Assert.Empty(convention1.Calls); + Assert.Empty(convention2.Calls); + scope.Dispose(); + } + + Assert.Equal(new[] { ("Cheese", (string)null) }, convention1.Calls); + Assert.Equal(new[] { ("Cheese", (string)null) }, convention2.Calls); + Assert.Empty(convention3.Calls); + + if (useBuilder) + { + Assert.NotNull(builder.HasEmbeddedDiscriminatorName("Cheese", ConfigurationSource.Convention)); + } + else + { + builder.Metadata.SetEmbeddedDiscriminatorName("Cheese", ConfigurationSource.Convention); + } + + Assert.Equal(new[] { ("Cheese", (string)null) }, convention1.Calls); + Assert.Equal(new[] { ("Cheese", (string)null) }, convention2.Calls); + Assert.Empty(convention3.Calls); + + if (useBuilder) + { + Assert.NotNull(builder.HasEmbeddedDiscriminatorName("Onion", ConfigurationSource.Convention)); + } + else + { + builder.Metadata.SetEmbeddedDiscriminatorName("Onion", ConfigurationSource.Convention); + } + + Assert.Equal(new[] { ("Cheese", null), ("Onion", "Cheese") }, convention1.Calls); + Assert.Equal(new[] { ("Cheese", null), ("Onion", "Cheese") }, convention2.Calls); + Assert.Empty(convention3.Calls); + + AssertSetOperations(new ModelEmbeddedDiscriminatorNameConvention(terminate: true), + conventions, conventions.ModelEmbeddedDiscriminatorNameConventions); + } + + private class ModelEmbeddedDiscriminatorNameConvention(bool terminate) : IModelEmbeddedDiscriminatorNameConvention + { + public readonly List<(string, string)> Calls = []; + + public void ProcessEmbeddedDiscriminatorName( + IConventionModelBuilder modelBuilder, string newName, string oldName, IConventionContext context) + { + Assert.NotNull(modelBuilder.Metadata.Builder); + + Calls.Add((newName, oldName)); + + if (terminate) + { + context.StopProcessing(); + } + } + } + [InlineData(false, false)] [InlineData(true, false)] [InlineData(false, true)]