Skip to content

Commit

Permalink
API review: Obsolete ForXxx methods in favor of shorter names
Browse files Browse the repository at this point in the history
Fixes #16686
  • Loading branch information
ajcvickers committed Jul 25, 2019
1 parent baecaef commit f377f2b
Show file tree
Hide file tree
Showing 47 changed files with 1,918 additions and 564 deletions.
34 changes: 17 additions & 17 deletions src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class CosmosEntityTypeBuilderExtensions
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder ForCosmosToContainer(
public static EntityTypeBuilder ToContainer(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name)
{
Expand All @@ -43,11 +43,11 @@ public static EntityTypeBuilder ForCosmosToContainer(
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder<TEntity> ForCosmosToContainer<TEntity>(
public static EntityTypeBuilder<TEntity> ToContainer<TEntity>(
[NotNull] this EntityTypeBuilder<TEntity> entityTypeBuilder,
[CanBeNull] string name)
where TEntity : class
=> (EntityTypeBuilder<TEntity>)ForCosmosToContainer((EntityTypeBuilder)entityTypeBuilder, name);
=> (EntityTypeBuilder<TEntity>)ToContainer((EntityTypeBuilder)entityTypeBuilder, name);

/// <summary>
/// Configures the container that the entity type maps to when targeting Azure Cosmos.
Expand All @@ -59,12 +59,12 @@ public static EntityTypeBuilder<TEntity> ForCosmosToContainer<TEntity>(
/// The same builder instance if the configuration was applied,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionEntityTypeBuilder ForCosmosToContainer(
public static IConventionEntityTypeBuilder ToContainer(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.ForCosmosCanSetContainer(name, fromDataAnnotation))
if (!entityTypeBuilder.CanSetContainer(name, fromDataAnnotation))
{
return null;
}
Expand All @@ -82,7 +82,7 @@ public static IConventionEntityTypeBuilder ForCosmosToContainer(
/// <param name="name"> The name of the container. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the configuration can be applied. </returns>
public static bool ForCosmosCanSetContainer(
public static bool CanSetContainer(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Expand All @@ -97,7 +97,7 @@ public static bool ForCosmosCanSetContainer(
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <param name="name"> The name of the parent property. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static OwnedNavigationBuilder ForCosmosToProperty(
public static OwnedNavigationBuilder ToJsonProperty(
[NotNull] this OwnedNavigationBuilder entityTypeBuilder,
[CanBeNull] string name)
{
Expand All @@ -112,7 +112,7 @@ public static OwnedNavigationBuilder ForCosmosToProperty(
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <param name="name"> The name of the parent property. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static OwnedNavigationBuilder<TEntity, TDependentEntity> ForCosmosToProperty<TEntity, TDependentEntity>(
public static OwnedNavigationBuilder<TEntity, TDependentEntity> ToJsonProperty<TEntity, TDependentEntity>(
[NotNull] this OwnedNavigationBuilder<TEntity, TDependentEntity> entityTypeBuilder,
[CanBeNull] string name)
where TEntity : class
Expand All @@ -133,12 +133,12 @@ public static OwnedNavigationBuilder<TEntity, TDependentEntity> ForCosmosToPrope
/// The same builder instance if the configuration was applied,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionEntityTypeBuilder ForCosmosToProperty(
public static IConventionEntityTypeBuilder ToJsonProperty(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.ForCosmosCanSetProperty(name, fromDataAnnotation))
if (!entityTypeBuilder.CanSetJsonProperty(name, fromDataAnnotation))
{
return null;
}
Expand All @@ -156,7 +156,7 @@ public static IConventionEntityTypeBuilder ForCosmosToProperty(
/// <param name="name"> The name of the parent property. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the configuration can be applied. </returns>
public static bool ForCosmosCanSetProperty(
public static bool CanSetJsonProperty(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Expand All @@ -171,7 +171,7 @@ public static bool ForCosmosCanSetProperty(
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <param name="name"> The name of the partition key property. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder ForCosmosHasPartitionKey(
public static EntityTypeBuilder HasPartitionKey(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name)
{
Expand All @@ -186,7 +186,7 @@ public static EntityTypeBuilder ForCosmosHasPartitionKey(
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <param name="name"> The name of the partition key property. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder<TEntity> ForCosmosHasPartitionKey<TEntity>(
public static EntityTypeBuilder<TEntity> HasPartitionKey<TEntity>(
[NotNull] this EntityTypeBuilder<TEntity> entityTypeBuilder,
[CanBeNull] string name)
where TEntity : class
Expand All @@ -202,7 +202,7 @@ public static EntityTypeBuilder<TEntity> ForCosmosHasPartitionKey<TEntity>(
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <param name="propertyExpression"> The partition key property. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder<TEntity> ForCosmosHasPartitionKey<TEntity, TProperty>(
public static EntityTypeBuilder<TEntity> HasPartitionKey<TEntity, TProperty>(
[NotNull] this EntityTypeBuilder<TEntity> entityTypeBuilder,
[NotNull] Expression<Func<TEntity, TProperty>> propertyExpression)
where TEntity : class
Expand All @@ -224,12 +224,12 @@ public static EntityTypeBuilder<TEntity> ForCosmosHasPartitionKey<TEntity, TProp
/// The same builder instance if the configuration was applied,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionEntityTypeBuilder ForCosmosHasPartitionKey(
public static IConventionEntityTypeBuilder HasPartitionKey(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.ForCosmosCanSetPartitionKey(name, fromDataAnnotation))
if (!entityTypeBuilder.CanSetPartitionKey(name, fromDataAnnotation))
{
return null;
}
Expand All @@ -247,7 +247,7 @@ public static IConventionEntityTypeBuilder ForCosmosHasPartitionKey(
/// <param name="name"> The name of the partition key property. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the configuration can be applied. </returns>
public static bool ForCosmosCanSetPartitionKey(
public static bool CanSetPartitionKey(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class CosmosModelBuilderExtensions
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="name"> The default container name. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder ForCosmosHasDefaultContainer(
public static ModelBuilder HasDefaultContainer(
[NotNull] this ModelBuilder modelBuilder,
[CanBeNull] string name)
{
Expand All @@ -44,12 +44,12 @@ public static ModelBuilder ForCosmosHasDefaultContainer(
/// The same builder instance if the configuration was applied,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionModelBuilder ForCosmosHasDefaultContainer(
public static IConventionModelBuilder HasDefaultContainer(
[NotNull] this IConventionModelBuilder modelBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
if (!modelBuilder.ForCosmosCanSetDefaultContainer(name, fromDataAnnotation))
if (!modelBuilder.CanSetDefaultContainer(name, fromDataAnnotation))
{
return null;
}
Expand All @@ -66,7 +66,7 @@ public static IConventionModelBuilder ForCosmosHasDefaultContainer(
/// <param name="name"> The default container name. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the given container name can be set as default. </returns>
public static bool ForCosmosCanSetDefaultContainer(
public static bool CanSetDefaultContainer(
[NotNull] this IConventionModelBuilder modelBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
Expand Down
12 changes: 6 additions & 6 deletions src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class CosmosPropertyBuilderExtensions
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder ForCosmosToProperty(
public static PropertyBuilder ToJsonProperty(
[NotNull] this PropertyBuilder propertyBuilder,
[NotNull] string name)
{
Expand All @@ -40,10 +40,10 @@ public static PropertyBuilder ForCosmosToProperty(
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder<TProperty> ForCosmosToProperty<TProperty>(
public static PropertyBuilder<TProperty> ToJsonProperty<TProperty>(
[NotNull] this PropertyBuilder<TProperty> propertyBuilder,
[NotNull] string name)
=> (PropertyBuilder<TProperty>)ForCosmosToProperty((PropertyBuilder)propertyBuilder, name);
=> (PropertyBuilder<TProperty>)ToJsonProperty((PropertyBuilder)propertyBuilder, name);

/// <summary>
/// <para>
Expand All @@ -60,12 +60,12 @@ public static PropertyBuilder<TProperty> ForCosmosToProperty<TProperty>(
/// The same builder instance if the configuration was applied,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionPropertyBuilder ForCosmosToProperty(
public static IConventionPropertyBuilder ToJsonProperty(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
{
if (!propertyBuilder.ForCosmosCanSetProperty(name, fromDataAnnotation))
if (!propertyBuilder.CanSetJsonProperty(name, fromDataAnnotation))
{
return null;
}
Expand All @@ -82,7 +82,7 @@ public static IConventionPropertyBuilder ForCosmosToProperty(
/// <param name="name"> The name of the container. </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 ForCosmosCanSetProperty(
public static bool CanSetJsonProperty(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
[CanBeNull] string name,
bool fromDataAnnotation = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public virtual void ProcessModelInitialized(
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(context, nameof(context));

modelBuilder.ForCosmosHasDefaultContainer(Dependencies.ContextType.Name);
modelBuilder.HasDefaultContainer(Dependencies.ContextType.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static void Process(IConventionEntityTypeBuilder entityTypeBuilder)
entityTypeBuilder.HasKey(new[] { idProperty.Metadata });

var jObjectProperty = entityTypeBuilder.Property(typeof(JObject), JObjectPropertyName);
jObjectProperty.ForCosmosToProperty("");
jObjectProperty.ToJsonProperty("");
jObjectProperty.ValueGenerated(ValueGenerated.OnAddOrUpdate);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public override bool IsHandledByConvention(IModel model, IAnnotation annotation)
public override MethodCallCodeFragment GenerateFluentApi(IKey key, IAnnotation annotation)
=> annotation.Name == SqlServerAnnotationNames.Clustered
? (bool)annotation.Value == false
? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered), false)
: new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered))
? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered), false)
: new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered))
: null;

/// <summary>
Expand All @@ -73,13 +73,13 @@ public override MethodCallCodeFragment GenerateFluentApi(IIndex index, IAnnotati
if (annotation.Name == SqlServerAnnotationNames.Clustered)
{
return (bool)annotation.Value == false
? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered), false)
: new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered));
? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered), false)
: new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered));
}

if (annotation.Name == SqlServerAnnotationNames.Include)
{
return new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerInclude), annotation.Value);
return new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IncludeProperties), annotation.Value);
}

return null;
Expand Down
Loading

0 comments on commit f377f2b

Please sign in to comment.