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

[automated] Merge branch 'release/8.0' => 'main' #31761

Merged
1 commit merged into from
Sep 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ private static readonly MethodInfo IndexHasFillFactorMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFillFactor), new[] { typeof(IndexBuilder), typeof(int) })!;

private static readonly MethodInfo IndexIsSortedInTempDbInfo
private static readonly MethodInfo IndexSortInTempDbMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.IsSortedInTempDb), new[] { typeof(IndexBuilder), typeof(bool) })!;
nameof(SqlServerIndexBuilderExtensions.SortInTempDb), new[] { typeof(IndexBuilder), typeof(bool) })!;

private static readonly MethodInfo IndexUseDataCompressionInfo
private static readonly MethodInfo IndexUseDataCompressionMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.UseDataCompression), new[] { typeof(IndexBuilder), typeof(DataCompressionType) })!;

Expand Down Expand Up @@ -349,8 +349,8 @@ protected override bool IsHandledByConvention(IProperty property, IAnnotation an

SqlServerAnnotationNames.Include => new MethodCallCodeFragment(IndexIncludePropertiesMethodInfo, annotation.Value),
SqlServerAnnotationNames.FillFactor => new MethodCallCodeFragment(IndexHasFillFactorMethodInfo, annotation.Value),
SqlServerAnnotationNames.SortedInTempDb => new MethodCallCodeFragment(IndexIsSortedInTempDbInfo, annotation.Value),
SqlServerAnnotationNames.DataCompression => new MethodCallCodeFragment(IndexUseDataCompressionInfo, annotation.Value),
SqlServerAnnotationNames.SortInTempDb => new MethodCallCodeFragment(IndexSortInTempDbMethodInfo, annotation.Value),
SqlServerAnnotationNames.DataCompression => new MethodCallCodeFragment(IndexUseDataCompressionMethodInfo, annotation.Value),

_ => null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override void Generate(IIndex index, CSharpRuntimeAnnotationCodeGenerator
annotations.Remove(SqlServerAnnotationNames.CreatedOnline);
annotations.Remove(SqlServerAnnotationNames.Include);
annotations.Remove(SqlServerAnnotationNames.FillFactor);
annotations.Remove(SqlServerAnnotationNames.SortedInTempDb);
annotations.Remove(SqlServerAnnotationNames.SortInTempDb);
annotations.Remove(SqlServerAnnotationNames.DataCompression);
}

Expand All @@ -121,7 +121,7 @@ public override void Generate(ITableIndex index, CSharpRuntimeAnnotationCodeGene
annotations.Remove(SqlServerAnnotationNames.CreatedOnline);
annotations.Remove(SqlServerAnnotationNames.Include);
annotations.Remove(SqlServerAnnotationNames.FillFactor);
annotations.Remove(SqlServerAnnotationNames.SortedInTempDb);
annotations.Remove(SqlServerAnnotationNames.SortInTempDb);
annotations.Remove(SqlServerAnnotationNames.DataCompression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ public static bool CanSetFillFactor(
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="sortedInTempDb">A value indicating whether the index is created with sort in tempdb option.</param>
/// <param name="sortInTempDb">A value indicating whether the index is created with sort in tempdb option.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder IsSortedInTempDb(this IndexBuilder indexBuilder, bool sortedInTempDb = true)
public static IndexBuilder SortInTempDb(this IndexBuilder indexBuilder, bool sortInTempDb = true)
{
indexBuilder.Metadata.SetIsSortedInTempDb(sortedInTempDb);
indexBuilder.Metadata.SetSortInTempDb(sortInTempDb);

return indexBuilder;
}
Expand All @@ -419,12 +419,12 @@ public static IndexBuilder IsSortedInTempDb(this IndexBuilder indexBuilder, bool
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="sortedInTempDb">A value indicating whether the index is created with sort in tempdb option.</param>
/// <param name="sortInTempDb">A value indicating whether the index is created with sort in tempdb option.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> IsSortedInTempDb<TEntity>(
public static IndexBuilder<TEntity> SortInTempDb<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
bool sortedInTempDb = true)
=> (IndexBuilder<TEntity>)IsSortedInTempDb((IndexBuilder)indexBuilder, sortedInTempDb);
bool sortInTempDb = true)
=> (IndexBuilder<TEntity>)SortInTempDb((IndexBuilder)indexBuilder, sortInTempDb);

/// <summary>
/// Configures whether the index is created with sort in tempdb option when targeting SQL Server.
Expand All @@ -435,20 +435,20 @@ public static IndexBuilder<TEntity> IsSortedInTempDb<TEntity>(
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="sortedInTempDb">A value indicating whether the index is created with sort in tempdb option.</param>
/// <param name="sortInTempDb">A value indicating whether the index is created with sort in tempdb option.</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,
/// <see langword="null" /> otherwise.
/// </returns>
public static IConventionIndexBuilder? IsSortedInTempDb(
public static IConventionIndexBuilder? SortInTempDb(
this IConventionIndexBuilder indexBuilder,
bool? sortedInTempDb,
bool? sortInTempDb,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetIsSortedInTempDb(sortedInTempDb, fromDataAnnotation))
if (indexBuilder.CanSetSortInTempDb(sortInTempDb, fromDataAnnotation))
{
indexBuilder.Metadata.SetIsSortedInTempDb(sortedInTempDb, fromDataAnnotation);
indexBuilder.Metadata.SetSortInTempDb(sortInTempDb, fromDataAnnotation);

return indexBuilder;
}
Expand All @@ -465,18 +465,18 @@ public static IndexBuilder<TEntity> IsSortedInTempDb<TEntity>(
/// for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="sortedInTempDb">A value indicating whether the index is created with sort in tempdb option.</param>
/// <param name="sortInTempDb">A value indicating whether the index is created with sort in tempdb option.</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,
/// <see langword="null" /> otherwise.
/// </returns>
/// <returns><see langword="true" /> if the index can be configured with sort in tempdb option when targeting SQL Server.</returns>
public static bool CanSetIsSortedInTempDb(
public static bool CanSetSortInTempDb(
this IConventionIndexBuilder indexBuilder,
bool? sortedInTempDb,
bool? sortInTempDb,
bool fromDataAnnotation = false)
=> indexBuilder.CanSetAnnotation(SqlServerAnnotationNames.SortedInTempDb, sortedInTempDb, fromDataAnnotation);
=> indexBuilder.CanSetAnnotation(SqlServerAnnotationNames.SortInTempDb, sortInTempDb, fromDataAnnotation);

/// <summary>
/// Configures whether the index is created with data compression option when targeting SQL Server.
Expand Down
32 changes: 16 additions & 16 deletions src/EFCore.SqlServer/Extensions/SqlServerIndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,67 +303,67 @@ public static void SetFillFactor(this IMutableIndex index, int? fillFactor)
/// </summary>
/// <param name="index">The index.</param>
/// <returns><see langword="true" /> if the index is sorted in tempdb.</returns>
public static bool? GetIsSortedInTempDb(this IReadOnlyIndex index)
public static bool? GetSortInTempDb(this IReadOnlyIndex index)
=> (index is RuntimeIndex)
? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)
: (bool?)index[SqlServerAnnotationNames.SortedInTempDb];
: (bool?)index[SqlServerAnnotationNames.SortInTempDb];

/// <summary>
/// Returns a value indicating whether the index is sorted in tempdb.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="storeObject">The identifier of the store object.</param>
/// <returns><see langword="true" /> if the index is sorted in tempdb.</returns>
public static bool? GetIsSortedInTempDb(this IReadOnlyIndex index, in StoreObjectIdentifier storeObject)
public static bool? GetSortInTempDb(this IReadOnlyIndex index, in StoreObjectIdentifier storeObject)
{
if (index is RuntimeIndex)
{
throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData);
}

var annotation = index.FindAnnotation(SqlServerAnnotationNames.SortedInTempDb);
var annotation = index.FindAnnotation(SqlServerAnnotationNames.SortInTempDb);
if (annotation != null)
{
return (bool?)annotation.Value;
}

var sharedTableRootIndex = index.FindSharedObjectRootIndex(storeObject);
return sharedTableRootIndex?.GetIsSortedInTempDb(storeObject);
return sharedTableRootIndex?.GetSortInTempDb(storeObject);
}

/// <summary>
/// Sets a value indicating whether the index is sorted in tempdb.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="sortedInTempDb">The value to set.</param>
public static void SetIsSortedInTempDb(this IMutableIndex index, bool? sortedInTempDb)
/// <param name="sortInTempDb">The value to set.</param>
public static void SetSortInTempDb(this IMutableIndex index, bool? sortInTempDb)
=> index.SetAnnotation(
SqlServerAnnotationNames.SortedInTempDb,
sortedInTempDb);
SqlServerAnnotationNames.SortInTempDb,
sortInTempDb);

/// <summary>
/// Sets a value indicating whether the index is sorted in tempdb.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="sortedInTempDb">The value to set.</param>
/// <param name="sortInTempDb">The value to set.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static bool? SetIsSortedInTempDb(
public static bool? SetSortInTempDb(
this IConventionIndex index,
bool? sortedInTempDb,
bool? sortInTempDb,
bool fromDataAnnotation = false)
=> (bool?)index.SetAnnotation(
SqlServerAnnotationNames.SortedInTempDb,
sortedInTempDb,
SqlServerAnnotationNames.SortInTempDb,
sortInTempDb,
fromDataAnnotation)?.Value;

/// <summary>
/// Returns the <see cref="ConfigurationSource" /> for whether the index is sorted in tempdb.
/// </summary>
/// <param name="index">The index.</param>
/// <returns>The <see cref="ConfigurationSource" /> for whether the index is sorted in tempdb.</returns>
public static ConfigurationSource? GetIsSortedInTempDbConfigurationSource(this IConventionIndex index)
=> index.FindAnnotation(SqlServerAnnotationNames.SortedInTempDb)?.GetConfigurationSource();
public static ConfigurationSource? GetSortInTempDbConfigurationSource(this IConventionIndex index)
=> index.FindAnnotation(SqlServerAnnotationNames.SortInTempDb)?.GetConfigurationSource();

/// <summary>
/// Returns the data compression that the index uses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected override void ProcessIndexAnnotations(
annotations.Remove(SqlServerAnnotationNames.CreatedOnline);
annotations.Remove(SqlServerAnnotationNames.Include);
annotations.Remove(SqlServerAnnotationNames.FillFactor);
annotations.Remove(SqlServerAnnotationNames.SortedInTempDb);
annotations.Remove(SqlServerAnnotationNames.SortInTempDb);
annotations.Remove(SqlServerAnnotationNames.DataCompression);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ 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 SortedInTempDb = Prefix + "SortInTempDb";
public const string SortInTempDb = Prefix + "SortInTempDb";

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ public override IEnumerable<IAnnotation> For(ITableIndex index, bool designTime)
yield return new Annotation(SqlServerAnnotationNames.FillFactor, fillFactor);
}

if (modelIndex.GetIsSortedInTempDb(table) is bool isSortedInTempDb)
if (modelIndex.GetSortInTempDb(table) is bool sortInTempDb)
{
yield return new Annotation(SqlServerAnnotationNames.SortedInTempDb, isSortedInTempDb);
yield return new Annotation(SqlServerAnnotationNames.SortInTempDb, sortInTempDb);
}

if (modelIndex.GetDataCompression(table) is DataCompressionType dataCompressionType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static bool AreCompatibleForSqlServer(
return false;
}

if (index.GetIsSortedInTempDb() != duplicateIndex.GetIsSortedInTempDb())
if (index.GetSortInTempDb() != duplicateIndex.GetSortInTempDb())
{
if (shouldThrow)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,7 @@ private static void IndexWithOptions(CreateIndexOperation operation, MigrationCo
options.Add("ONLINE = ON");
}

if (operation[SqlServerAnnotationNames.SortedInTempDb] is bool isSortedInTempDb && isSortedInTempDb)
if (operation[SqlServerAnnotationNames.SortInTempDb] is bool sortInTempDb && sortInTempDb)
{
options.Add("SORT_IN_TEMPDB = ON");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6284,12 +6284,12 @@ public virtual void IndexAttribute_UseDataCompression_is_stored_in_snapshot()
});

[ConditionalFact]
public virtual void IndexAttribute_IsSortedInTempDb_is_stored_in_snapshot()
public virtual void IndexAttribute_SortInTempDb_is_stored_in_snapshot()
=> Test(
builder => builder.Entity<EntityWithStringProperty>(
x =>
{
x.HasIndex(e => e.Id).IsSortedInTempDb(true);
x.HasIndex(e => e.Id).SortInTempDb(true);
}),
AddBoilerPlate(
GetHeading() +
Expand All @@ -6309,15 +6309,15 @@ public virtual void IndexAttribute_IsSortedInTempDb_is_stored_in_snapshot()

b.HasIndex("Id");

SqlServerIndexBuilderExtensions.IsSortedInTempDb(b.HasIndex("Id"), true);
SqlServerIndexBuilderExtensions.SortInTempDb(b.HasIndex("Id"), true);

b.ToTable("EntityWithStringProperty", "DefaultSchema");
});
"""),
model =>
{
var index = model.GetEntityTypes().First().GetIndexes().First();
Assert.True(index.GetIsSortedInTempDb());
Assert.True(index.GetSortInTempDb());
});

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14827,10 +14827,10 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType)
Assert.Equal(
CoreStrings.RuntimeModelMissingData,
Assert.Throws<InvalidOperationException>(() => alternateIndex.GetIncludeProperties()).Message);
Assert.Null(alternateIndex[SqlServerAnnotationNames.SortedInTempDb]);
Assert.Null(alternateIndex[SqlServerAnnotationNames.SortInTempDb]);
Assert.Equal(
CoreStrings.RuntimeModelMissingData,
Assert.Throws<InvalidOperationException>(() => alternateIndex.GetIsSortedInTempDb()).Message);
Assert.Throws<InvalidOperationException>(() => alternateIndex.GetSortInTempDb()).Message);
Assert.Null(alternateIndex[SqlServerAnnotationNames.DataCompression]);
Assert.Equal(
CoreStrings.RuntimeModelMissingData,
Expand Down Expand Up @@ -15054,7 +15054,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.IsCreatedOnline()
.HasFillFactor(40)
.IncludeProperties(e => e.Id)
.IsSortedInTempDb()
.SortInTempDb()
.UseDataCompression(DataCompressionType.Page);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,7 @@ await Test(
.IsUnique()
.IncludeProperties("FirstName", "LastName")
.HasFillFactor(75)
.IsSortedInTempDb(),
.SortInTempDb(),
model =>
{
var table = Assert.Single(model.Tables);
Expand All @@ -2254,7 +2254,7 @@ await Test(
var includedColumns = (IReadOnlyList<string>?)index[SqlServerAnnotationNames.Include];
Assert.Null(includedColumns);
Assert.Equal(75, index[SqlServerAnnotationNames.FillFactor]);
Assert.Null(index[SqlServerAnnotationNames.SortedInTempDb]);
Assert.Null(index[SqlServerAnnotationNames.SortInTempDb]);
});

AssertSql(
Expand Down Expand Up @@ -2292,7 +2292,7 @@ await Test(
builder => builder.Entity("People").HasIndex("Name")
.IsUnique()
.IncludeProperties("FirstName", "LastName")
.IsSortedInTempDb()
.SortInTempDb()
.UseDataCompression(dataCompression),
model =>
{
Expand All @@ -2304,7 +2304,7 @@ await Test(
Assert.Contains(table.Columns.Single(c => c.Name == "Name"), index.Columns);
var includedColumns = (IReadOnlyList<string>?)index[SqlServerAnnotationNames.Include];
Assert.Null(includedColumns);
Assert.Null(index[SqlServerAnnotationNames.SortedInTempDb]);
Assert.Null(index[SqlServerAnnotationNames.SortInTempDb]);
Assert.Null(index[SqlServerAnnotationNames.DataCompression]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void CreateIndexOperation_unique_sortintempdb()
Schema = "dbo",
Columns = new[] { "FirstName", "LastName" },
IsUnique = true,
[SqlServerAnnotationNames.SortedInTempDb] = true
[SqlServerAnnotationNames.SortInTempDb] = true
});

AssertSql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public virtual void Detects_duplicate_index_names_within_hierarchy_different_sor
var modelBuilder = CreateConventionModelBuilder();
modelBuilder.Entity<Animal>();
modelBuilder.Entity<Cat>().HasIndex(c => c.Name).HasDatabaseName("IX_Animal_Name");
modelBuilder.Entity<Dog>().HasIndex(d => d.Name).HasDatabaseName("IX_Animal_Name").IsSortedInTempDb();
modelBuilder.Entity<Dog>().HasIndex(d => d.Name).HasDatabaseName("IX_Animal_Name").SortInTempDb();

VerifyError(
SqlServerStrings.DuplicateIndexSortInTempDbMismatch(
Expand Down
Loading
Loading