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

Tweak the API for Azure edition options. #18544

Merged
merged 1 commit into from
Oct 23, 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
90 changes: 66 additions & 24 deletions src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,42 @@ public static bool CanSetDatabaseMaxSize(

/// <summary>
/// <para>
/// Configures the service tier (EDITION) for Azure SQL Database.
/// Configures the service tier (EDITION) for Azure SQL Database as a string literal.
/// </para>
/// <para>
/// Literals should be delimited with ''. See Azure SQL Database documentation for supported values.
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="serviceTier"> The service tier of the database. </param>
/// <param name="serviceTier"> The service tier of the database as a string literal. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder HasServiceTier([NotNull] this ModelBuilder modelBuilder, [NotNull] string serviceTier)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(serviceTier, nameof(serviceTier));

modelBuilder.Model.SetServiceTier(serviceTier);
modelBuilder.Model.SetServiceTierSql("'" + serviceTier.Replace("'", "''") + "'");

return modelBuilder;
}

/// <summary>
/// <para>
/// Configures the service tier (EDITION) for Azure SQL Database as a SQL expression.
/// </para>
/// <para>
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="serviceTier"> The expression for the service tier of the database. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder HasServiceTierSql([NotNull] this ModelBuilder modelBuilder, [NotNull] string serviceTier)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(serviceTier, nameof(serviceTier));

modelBuilder.Model.SetServiceTierSql(serviceTier);

return modelBuilder;
}
Expand All @@ -343,22 +364,22 @@ public static ModelBuilder HasServiceTier([NotNull] this ModelBuilder modelBuild
/// Attempts to configure the service tier (EDITION) for Azure SQL Database.
/// </para>
/// <para>
/// Literals should be delimited with ''. See Azure SQL Database documentation for supported values.
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="serviceTier"> The service tier of the database. </param>
/// <param name="serviceTier"> The expression for the service tier of the database. </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,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionModelBuilder HasServiceTier(
public static IConventionModelBuilder HasServiceTierSql(
[NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string serviceTier, bool fromDataAnnotation = false)
{
if (modelBuilder.CanSetServiceTier(serviceTier, fromDataAnnotation))
if (modelBuilder.CanSetServiceTierSql(serviceTier, fromDataAnnotation))
{
modelBuilder.Metadata.SetServiceTier(serviceTier, fromDataAnnotation);
modelBuilder.Metadata.SetServiceTierSql(serviceTier, fromDataAnnotation);
return modelBuilder;
}

Expand All @@ -369,34 +390,55 @@ public static IConventionModelBuilder HasServiceTier(
/// Returns a value indicating whether the given value can be set as the service tier of the database.
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="serviceTier"> The service tier of the database. </param>
/// <param name="serviceTier"> The expression for the service tier of the database. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the given value can be set as the service tier of the database. </returns>
public static bool CanSetServiceTier(
public static bool CanSetServiceTierSql(
[NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string serviceTier, bool fromDataAnnotation = false)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));

return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.ServiceTier, serviceTier, fromDataAnnotation);
return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.ServiceTierSql, serviceTier, fromDataAnnotation);
}

/// <summary>
/// <para>
/// Configures the performance level (SERVICE_OBJECTIVE) for Azure SQL Database.
/// Configures the performance level (SERVICE_OBJECTIVE) for Azure SQL Database as a string literal.
/// </para>
/// <para>
/// Literals should be delimited with ''. See Azure SQL Database documentation for supported values.
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="performanceLevel"> The performance level of the database. </param>
/// <param name="performanceLevel"> The performance level of the database as a string literal. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder HasPerformanceLevel([NotNull] this ModelBuilder modelBuilder, [NotNull] string performanceLevel)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(performanceLevel, nameof(performanceLevel));

modelBuilder.Model.SetPerformanceLevel(performanceLevel);
modelBuilder.Model.SetPerformanceLevelSql("'" + performanceLevel.Replace("'", "''") + "'");

return modelBuilder;
}

/// <summary>
/// <para>
/// Configures the performance level (SERVICE_OBJECTIVE) for Azure SQL Database as a SQL expression.
/// </para>
/// <para>
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="performanceLevel"> The expression for the performance level of the database. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ModelBuilder HasPerformanceLevelSql([NotNull] this ModelBuilder modelBuilder, [NotNull] string performanceLevel)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(performanceLevel, nameof(performanceLevel));

modelBuilder.Model.SetPerformanceLevelSql(performanceLevel);

return modelBuilder;
}
Expand All @@ -406,22 +448,22 @@ public static ModelBuilder HasPerformanceLevel([NotNull] this ModelBuilder model
/// Attempts to configure the performance level (SERVICE_OBJECTIVE) for Azure SQL Database.
/// </para>
/// <para>
/// Literals should be delimited with ''. See Azure SQL Database documentation for supported values.
/// See Azure SQL Database documentation for supported values.
/// </para>
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="performanceLevel"> The performance level of the database. </param>
/// <param name="performanceLevel"> The expression for the performance level of the database. </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,
/// <c>null</c> otherwise.
/// </returns>
public static IConventionModelBuilder HasPerformanceLevel(
public static IConventionModelBuilder HasPerformanceLevelSql(
[NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string performanceLevel, bool fromDataAnnotation = false)
{
if (modelBuilder.CanSetPerformanceLevel(performanceLevel, fromDataAnnotation))
if (modelBuilder.CanSetPerformanceLevelSql(performanceLevel, fromDataAnnotation))
{
modelBuilder.Metadata.SetPerformanceLevel(performanceLevel, fromDataAnnotation);
modelBuilder.Metadata.SetPerformanceLevelSql(performanceLevel, fromDataAnnotation);
return modelBuilder;
}

Expand All @@ -432,15 +474,15 @@ public static IConventionModelBuilder HasPerformanceLevel(
/// Returns a value indicating whether the given value can be set as the performance level of the database.
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="performanceLevel"> The performance level of the database. </param>
/// <param name="performanceLevel"> The performance level of the database expression. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> <c>true</c> if the given value can be set as the performance level of the database. </returns>
public static bool CanSetPerformanceLevel(
public static bool CanSetPerformanceLevelSql(
[NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string performanceLevel, bool fromDataAnnotation = false)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));

return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.PerformanceLevel, performanceLevel, fromDataAnnotation);
return modelBuilder.CanSetAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, performanceLevel, fromDataAnnotation);
}

/// <summary>
Expand Down
34 changes: 17 additions & 17 deletions src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,75 +250,75 @@ public static void SetDatabaseMaxSize(
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the maximum size of the database. </returns>
public static ConfigurationSource? GetMaxSizeConfigurationSource([NotNull] this IConventionModel model)
public static ConfigurationSource? GetDatabaseMaxSizeConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.MaxDatabaseSize)?.GetConfigurationSource();

/// <summary>
/// Returns the service tier of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The service tier of the database. </returns>
public static string GetServiceTier([NotNull] this IModel model)
=> (string)model[SqlServerAnnotationNames.ServiceTier];
public static string GetServiceTierSql([NotNull] this IModel model)
=> (string)model[SqlServerAnnotationNames.ServiceTierSql];

/// <summary>
/// Sets the service tier of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <param name="value"> The value to set. </param>
public static void SetServiceTier([NotNull] this IMutableModel model, [CanBeNull] string value)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTier, value);
public static void SetServiceTierSql([NotNull] this IMutableModel model, [CanBeNull] string value)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTierSql, value);

/// <summary>
/// Sets the service tier of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <param name="value"> The value to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetServiceTier(
public static void SetServiceTierSql(
[NotNull] this IConventionModel model, [CanBeNull] string value, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTier, value, fromDataAnnotation);
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTierSql, value, fromDataAnnotation);

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for the service tier of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the service tier of the database. </returns>
public static ConfigurationSource? GetServiceTierConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.ServiceTier)?.GetConfigurationSource();
public static ConfigurationSource? GetServiceTierSqlConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.ServiceTierSql)?.GetConfigurationSource();

/// <summary>
/// Returns the performance level of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The performance level of the database. </returns>
public static string GetPerformanceLevel([NotNull] this IModel model)
=> (string)model[SqlServerAnnotationNames.PerformanceLevel];
public static string GetPerformanceLevelSql([NotNull] this IModel model)
=> (string)model[SqlServerAnnotationNames.PerformanceLevelSql];

/// <summary>
/// Sets the performance level of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <param name="value"> The value to set. </param>
public static void SetPerformanceLevel([NotNull] this IMutableModel model, [CanBeNull] string value)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevel, value);
public static void SetPerformanceLevelSql([NotNull] this IMutableModel model, [CanBeNull] string value)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, value);

/// <summary>
/// Sets the performance level of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <param name="value"> The value to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetPerformanceLevel(
public static void SetPerformanceLevelSql(
[NotNull] this IConventionModel model, [CanBeNull] string value, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevel, value, fromDataAnnotation);
=> model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, value, fromDataAnnotation);

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for the performance level of the database.
/// </summary>
/// <param name="model"> The model. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the performance level of the database. </returns>
public static ConfigurationSource? GetPerformanceLevelConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.PerformanceLevel)?.GetConfigurationSource();
public static ConfigurationSource? GetPerformanceLevelSqlConfigurationSource([NotNull] this IConventionModel model)
=> model.FindAnnotation(SqlServerAnnotationNames.PerformanceLevelSql)?.GetConfigurationSource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ public static class SqlServerAnnotationNames
/// 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.
/// </summary>
public const string ServiceTier = Prefix + "ServiceTier";
public const string ServiceTierSql = Prefix + "ServiceTierSql";

/// <summary>
/// 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.
/// </summary>
public const string PerformanceLevel = Prefix + "PerformanceLevel";
public const string PerformanceLevelSql = Prefix + "PerformanceLevelSql";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down Expand Up @@ -48,8 +47,8 @@ public SqlServerMigrationsAnnotationProvider([NotNull] MigrationsAnnotationProvi
public override IEnumerable<IAnnotation> For(IModel model)
{
var maxSize = model.GetDatabaseMaxSize();
var serviceTier = model.GetServiceTier();
var performanceLevel = model.GetPerformanceLevel();
var serviceTier = model.GetServiceTierSql();
var performanceLevel = model.GetPerformanceLevelSql();
if (maxSize != null
|| serviceTier != null
|| performanceLevel != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ public virtual void Model_annotations_are_stored_in_snapshot()
Test(
builder => builder.HasAnnotation("AnnotationName", "AnnotationValue")
.HasDatabaseMaxSize("100 MB")
.HasServiceTier("'basic'")
.HasPerformanceLevel("'S0'"),
.HasServiceTier("basic")
.HasPerformanceLevel("S0"),
AddBoilerPlate(
@"
modelBuilder
.HasAnnotation(""AnnotationName"", ""AnnotationValue"")
.HasAnnotation(""Relational:MaxIdentifierLength"", 128)
.HasAnnotation(""SqlServer:DatabaseMaxSize"", ""100 MB"")
.HasAnnotation(""SqlServer:PerformanceLevel"", ""'S0'"")
.HasAnnotation(""SqlServer:ServiceTier"", ""'basic'"")
.HasAnnotation(""SqlServer:PerformanceLevelSql"", ""'S0'"")
.HasAnnotation(""SqlServer:ServiceTierSql"", ""'basic'"")
.HasAnnotation(""SqlServer:ValueGenerationStrategy"", SqlServerValueGenerationStrategy.IdentityColumn);"),
o =>
{
Expand Down
Loading