Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos: Rename Get/SetPropertyName to Get/SetJsonPropertyName #18972

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class CosmosPropertyBuilderExtensions
/// </summary>
/// <remarks> If an empty string is supplied then the property will not be persisted. </remarks>
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <param name="name"> The name of the property. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder ToJsonProperty(
[NotNull] this PropertyBuilder propertyBuilder,
Expand All @@ -28,7 +28,7 @@ public static PropertyBuilder ToJsonProperty(
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
Check.NotNull(name, nameof(name));
smitpatel marked this conversation as resolved.
Show resolved Hide resolved

propertyBuilder.Metadata.SetPropertyName(name);
propertyBuilder.Metadata.SetJsonPropertyName(name);

return propertyBuilder;
}
Expand All @@ -38,7 +38,7 @@ public static PropertyBuilder ToJsonProperty(
/// </summary>
/// <typeparam name="TProperty"> The type of the property being configured. </typeparam>
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <param name="name"> The name of the property. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder<TProperty> ToJsonProperty<TProperty>(
[NotNull] this PropertyBuilder<TProperty> propertyBuilder,
Expand All @@ -54,7 +54,7 @@ public static PropertyBuilder<TProperty> ToJsonProperty<TProperty>(
/// </para>
/// </summary>
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <param name="name"> The name of the property. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns>
/// The same builder instance if the configuration was applied,
Expand All @@ -70,7 +70,7 @@ public static IConventionPropertyBuilder ToJsonProperty(
return null;
}

propertyBuilder.Metadata.SetPropertyName(name, fromDataAnnotation);
propertyBuilder.Metadata.SetJsonPropertyName(name, fromDataAnnotation);

return propertyBuilder;
}
Expand All @@ -79,7 +79,7 @@ public static IConventionPropertyBuilder ToJsonProperty(
/// Returns a value indicating whether the given property name can be set.
/// </summary>
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <param name="name"> The name of the property. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the property name can be set. </returns>
public static bool CanSetJsonProperty(
Expand Down
26 changes: 14 additions & 12 deletions src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ namespace Microsoft.EntityFrameworkCore
public static class CosmosPropertyExtensions
{
/// <summary>
/// Returns the property name used when targeting Cosmos.
/// Returns the property name that the property is mapped to when targeting Cosmos.
/// </summary>
/// <param name="property"> The property. </param>
/// <returns> The property name used when targeting Cosmos. </returns>
public static string GetPropertyName([NotNull] this IProperty property) =>
/// <returns> Returns the property name that the property is mapped to when targeting Cosmos. </returns>
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();
Expand All @@ -45,34 +45,36 @@ private static string GetDefaultPropertyName(IProperty property)
}

/// <summary>
/// Sets the property name used when targeting Cosmos.
/// Sets the property name that the property is mapped to when targeting Cosmos.
/// </summary>
/// <param name="property"> The property. </param>
/// <param name="name"> The name to set. </param>
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);

/// <summary>
/// Sets the property name used when targeting Cosmos.
/// Sets the property name that the property is mapped to when targeting Cosmos.
/// </summary>
/// <param name="property"> The property. </param>
/// <param name="name"> The name to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetPropertyName(
public static void SetJsonPropertyName(
[NotNull] this IConventionProperty property, [CanBeNull] string name, bool fromDataAnnotation = false)
=> property.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
name,
fromDataAnnotation);

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the property name used when targeting Cosmos.
/// Gets the <see cref="ConfigurationSource" /> the property name that the property is mapped to when targeting Cosmos.
/// </summary>
/// <param name="property"> The property. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the property name used when targeting Cosmos. </returns>
public static ConfigurationSource? GetPropertyNameConfigurationSource([NotNull] this IConventionProperty property)
/// <returns>
/// The <see cref="ConfigurationSource" /> the property name that the property is mapped to when targeting Cosmos.
/// </returns>
public static ConfigurationSource? GetJsonPropertyNameConfigurationSource([NotNull] this IConventionProperty property)
=> property.FindAnnotation(CosmosAnnotationNames.PropertyName)?.GetConfigurationSource();
}
}
6 changes: 3 additions & 3 deletions src/EFCore.Cosmos/Internal/CosmosModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down Expand Up @@ -259,7 +259,7 @@ private Task<bool> SaveAsync(IUpdateEntry entry, CancellationToken cancellationT
{
document = documentSource.CreateDocument(entry);

var propertyName = entityType.GetDiscriminatorProperty()?.GetPropertyName();
var propertyName = entityType.GetDiscriminatorProperty()?.GetJsonPropertyName();
if (propertyName != null)
{
document[propertyName] =
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Cosmos/Update/Internal/DocumentSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down