diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs index 5d4494c0598..d100bf553e0 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs @@ -19,7 +19,7 @@ public static class CosmosPropertyBuilderExtensions /// /// If an empty string is supplied then the property will not be persisted. /// The builder for the property being configured. - /// The name of the container. + /// The name of the property. /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder ToJsonProperty( [NotNull] this PropertyBuilder propertyBuilder, @@ -28,7 +28,7 @@ public static PropertyBuilder ToJsonProperty( Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NotNull(name, nameof(name)); - propertyBuilder.Metadata.SetPropertyName(name); + propertyBuilder.Metadata.SetJsonPropertyName(name); return propertyBuilder; } @@ -38,7 +38,7 @@ public static PropertyBuilder ToJsonProperty( /// /// The type of the property being configured. /// The builder for the property being configured. - /// The name of the container. + /// The name of the property. /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder ToJsonProperty( [NotNull] this PropertyBuilder propertyBuilder, @@ -54,7 +54,7 @@ public static PropertyBuilder ToJsonProperty( /// /// /// The builder for the property being configured. - /// The name of the container. + /// The name of the property. /// Indicates whether the configuration was specified using a data annotation. /// /// The same builder instance if the configuration was applied, @@ -70,7 +70,7 @@ public static IConventionPropertyBuilder ToJsonProperty( return null; } - propertyBuilder.Metadata.SetPropertyName(name, fromDataAnnotation); + propertyBuilder.Metadata.SetJsonPropertyName(name, fromDataAnnotation); return propertyBuilder; } @@ -79,7 +79,7 @@ public static IConventionPropertyBuilder ToJsonProperty( /// Returns a value indicating whether the given property name can be set. /// /// The builder for the property being configured. - /// The name of the container. + /// The name of the property. /// Indicates whether the configuration was specified using a data annotation. /// true if the property name can be set. public static bool CanSetJsonProperty( diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs index 4fa98985825..1c81f856df0 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs @@ -15,15 +15,15 @@ namespace Microsoft.EntityFrameworkCore public static class CosmosPropertyExtensions { /// - /// Returns the property name used when targeting Cosmos. + /// Returns the property name that the property is mapped to when targeting Cosmos. /// /// The property. - /// The property name used when targeting Cosmos. - public static string GetPropertyName([NotNull] this IProperty property) => + /// Returns the property name that the property is mapped to when targeting Cosmos. + public static string GetJsonPropertyName([NotNull] this IProperty property) => (string)property[CosmosAnnotationNames.PropertyName] - ?? GetDefaultPropertyName(property); + ?? GetDefaultJsonPropertyName(property); - private static string GetDefaultPropertyName(IProperty property) + private static string GetDefaultJsonPropertyName(IProperty property) { var entityType = property.DeclaringEntityType; var ownership = entityType.FindOwnership(); @@ -45,22 +45,22 @@ private static string GetDefaultPropertyName(IProperty property) } /// - /// Sets the property name used when targeting Cosmos. + /// Sets the property name that the property is mapped to when targeting Cosmos. /// /// The property. /// The name to set. - public static void SetPropertyName([NotNull] this IMutableProperty property, [CanBeNull] string name) + public static void SetJsonPropertyName([NotNull] this IMutableProperty property, [CanBeNull] string name) => property.SetOrRemoveAnnotation( CosmosAnnotationNames.PropertyName, name); /// - /// Sets the property name used when targeting Cosmos. + /// Sets the property name that the property is mapped to when targeting Cosmos. /// /// The property. /// The name to set. /// Indicates whether the configuration was specified using a data annotation. - public static void SetPropertyName( + public static void SetJsonPropertyName( [NotNull] this IConventionProperty property, [CanBeNull] string name, bool fromDataAnnotation = false) => property.SetOrRemoveAnnotation( CosmosAnnotationNames.PropertyName, @@ -68,11 +68,13 @@ public static void SetPropertyName( fromDataAnnotation); /// - /// Gets the for the property name used when targeting Cosmos. + /// Gets the the property name that the property is mapped to when targeting Cosmos. /// /// The property. - /// The for the property name used when targeting Cosmos. - public static ConfigurationSource? GetPropertyNameConfigurationSource([NotNull] this IConventionProperty property) + /// + /// The the property name that the property is mapped to when targeting Cosmos. + /// + public static ConfigurationSource? GetJsonPropertyNameConfigurationSource([NotNull] this IConventionProperty property) => property.FindAnnotation(CosmosAnnotationNames.PropertyName)?.GetConfigurationSource(); } } diff --git a/src/EFCore.Cosmos/Internal/CosmosModelValidator.cs b/src/EFCore.Cosmos/Internal/CosmosModelValidator.cs index e5193e403ed..12298ab23d9 100644 --- a/src/EFCore.Cosmos/Internal/CosmosModelValidator.cs +++ b/src/EFCore.Cosmos/Internal/CosmosModelValidator.cs @@ -123,12 +123,12 @@ protected virtual void ValidateSharedContainerCompatibility( partitionKey = nextPartitionKeyProperty; } - else if (partitionKey.GetPropertyName() != nextPartitionKeyProperty.GetPropertyName()) + else if (partitionKey.GetJsonPropertyName() != nextPartitionKeyProperty.GetJsonPropertyName()) { throw new InvalidOperationException( CosmosStrings.PartitionKeyStoreNameMismatch( - partitionKey.Name, firstEntityType.DisplayName(), partitionKey.GetPropertyName(), - nextPartitionKeyProperty.Name, entityType.DisplayName(), nextPartitionKeyProperty.GetPropertyName())); + partitionKey.Name, firstEntityType.DisplayName(), partitionKey.GetJsonPropertyName(), + nextPartitionKeyProperty.Name, entityType.DisplayName(), nextPartitionKeyProperty.GetJsonPropertyName())); } } else if (partitionKey != null) diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs index 735931ccdf2..e17667c1592 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs @@ -594,7 +594,7 @@ private Expression CreateGetValueExpression( return _projectionBindings[jObjectExpression]; } - var storeName = property.GetPropertyName(); + var storeName = property.GetJsonPropertyName(); if (storeName.Length == 0) { var entityType = property.DeclaringEntityType; diff --git a/src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs b/src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs index 2ede288c261..1734fe749bd 100644 --- a/src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs @@ -25,7 +25,7 @@ public class KeyAccessExpression : SqlExpression, IAccessExpression public KeyAccessExpression(IProperty property, Expression accessExpression) : base(property.ClrType, property.GetTypeMapping()) { - Name = property.GetPropertyName(); + Name = property.GetJsonPropertyName(); Property = property; AccessExpression = accessExpression; } diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs index 9b620b258fa..09833884aef 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs @@ -185,7 +185,7 @@ private static string GetPartitionKeyStoreName([NotNull] IEntityType entityType) var name = entityType.GetPartitionKeyPropertyName(); if (name != null) { - return entityType.FindProperty(name).GetPropertyName(); + return entityType.FindProperty(name).GetJsonPropertyName(); } return CosmosClientWrapper.DefaultPartitionKey; diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs index 9e3761876a0..1ab86f24d0c 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs @@ -204,7 +204,7 @@ private bool Save(IUpdateEntry entry) { document = documentSource.CreateDocument(entry); - var propertyName = entityType.GetDiscriminatorProperty()?.GetPropertyName(); + var propertyName = entityType.GetDiscriminatorProperty()?.GetJsonPropertyName(); if (propertyName != null) { document[propertyName] = @@ -259,7 +259,7 @@ private Task SaveAsync(IUpdateEntry entry, CancellationToken cancellationT { document = documentSource.CreateDocument(entry); - var propertyName = entityType.GetDiscriminatorProperty()?.GetPropertyName(); + var propertyName = entityType.GetDiscriminatorProperty()?.GetJsonPropertyName(); if (propertyName != null) { document[propertyName] = diff --git a/src/EFCore.Cosmos/Update/Internal/DocumentSource.cs b/src/EFCore.Cosmos/Update/Internal/DocumentSource.cs index 54a0c9d4ed4..5f9488625cb 100644 --- a/src/EFCore.Cosmos/Update/Internal/DocumentSource.cs +++ b/src/EFCore.Cosmos/Update/Internal/DocumentSource.cs @@ -68,7 +68,7 @@ public virtual JObject CreateDocument(IUpdateEntry entry) var document = new JObject(); foreach (var property in entry.EntityType.GetProperties()) { - var storeName = property.GetPropertyName(); + var storeName = property.GetJsonPropertyName(); if (storeName.Length != 0) { document[storeName] = ConvertPropertyValue(property, entry.GetCurrentValue(property)); @@ -130,7 +130,7 @@ public virtual JObject UpdateDocument(JObject document, IUpdateEntry entry) if (entry.EntityState == EntityState.Added || entry.IsModified(property)) { - var storeName = property.GetPropertyName(); + var storeName = property.GetJsonPropertyName(); if (storeName.Length != 0) { document[storeName] = ConvertPropertyValue(property, entry.GetCurrentValue(property)); diff --git a/src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs b/src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs index 0917da3e26b..a29951be860 100644 --- a/src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs +++ b/src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs @@ -19,7 +19,7 @@ public override ValueGenerator Create(IProperty property, IEntityType entityType { var type = property.ClrType.UnwrapNullableType().UnwrapEnumType(); - if (property.GetPropertyName() == "" + if (property.GetJsonPropertyName() == "" && type == typeof(int)) { return new TemporaryIntValueGenerator();