Skip to content

Commit

Permalink
Add GetSchemaQualifiedHistoryTableName method to SqlServerEntityTypeE…
Browse files Browse the repository at this point in the history
…xtensions (#35018) (#35368)

Add GetSchemaQualifiedHistoryTableName method to SqlServerEntityTypeExtensions

Fixes #35018

Co-authored-by: r.ghadimi <[email protected]>
  • Loading branch information
rezaghadimim and r.ghadimi authored Jan 7, 2025
1 parent c434d6c commit 6119066
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,25 @@ public static void SetHistoryTableSchema(this IMutableEntityType entityType, str
public static ConfigurationSource? GetHistoryTableSchemaConfigurationSource(this IConventionEntityType entityType)
=> entityType.FindAnnotation(SqlServerAnnotationNames.TemporalHistoryTableSchema)?.GetConfigurationSource();

/// <summary>
/// Returns the name of the history table to which the entity type is mapped prepended by the schema
/// or <see langword="null" /> if not mapped to a table.
/// </summary>
/// <param name="entityType">The entity type to get the history table name for.</param>
/// <returns>The name of the history table to which the entity type is mapped prepended by the schema.</returns>
public static string? GetSchemaQualifiedHistoryTableName(this IReadOnlyEntityType entityType)
{
var historyTableName = entityType.GetHistoryTableName();
if (historyTableName == null)
{
return null;
}

var schema = entityType.GetHistoryTableSchema();

return (string.IsNullOrEmpty(schema) ? "" : schema + ".") + historyTableName;
}

#endregion Temporal table

#region SQL OUTPUT clause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ public virtual void Temporal_table_default_settings()
Assert.True(entity.IsTemporal());
Assert.Equal("CustomerHistory", entity.GetHistoryTableName());
Assert.Null(entity.GetHistoryTableSchema());
Assert.Equal("CustomerHistory", entity.GetSchemaQualifiedHistoryTableName());

var periodStart = entity.GetProperty(entity.GetPeriodStartPropertyName()!);
var periodEnd = entity.GetProperty(entity.GetPeriodEndPropertyName()!);
Expand Down Expand Up @@ -1257,6 +1258,7 @@ public virtual void Temporal_table_with_history_table_configuration()

Assert.Equal("HistoryTable", entity.GetHistoryTableName());
Assert.Equal("historySchema", entity.GetHistoryTableSchema());
Assert.Equal("historySchema.HistoryTable", entity.GetSchemaQualifiedHistoryTableName());

var periodStart = entity.GetProperty(entity.GetPeriodStartPropertyName()!);
var periodEnd = entity.GetProperty(entity.GetPeriodEndPropertyName()!);
Expand Down Expand Up @@ -1306,6 +1308,7 @@ public virtual void Temporal_table_with_changed_configuration()

Assert.Equal("ChangedHistoryTable", entity.GetHistoryTableName());
Assert.Equal("changedHistorySchema", entity.GetHistoryTableSchema());
Assert.Equal("changedHistorySchema.ChangedHistoryTable", entity.GetSchemaQualifiedHistoryTableName());

var periodStart = entity.GetProperty(entity.GetPeriodStartPropertyName()!);
var periodEnd = entity.GetProperty(entity.GetPeriodEndPropertyName()!);
Expand Down Expand Up @@ -1355,6 +1358,7 @@ public virtual void Temporal_table_with_period_column_names_changed_configuratio

Assert.Equal("ChangedHistoryTable", entity.GetHistoryTableName());
Assert.Equal("changedHistorySchema", entity.GetHistoryTableSchema());
Assert.Equal("changedHistorySchema.ChangedHistoryTable", entity.GetSchemaQualifiedHistoryTableName());

var periodStart = entity.GetProperty(entity.GetPeriodStartPropertyName()!);
var periodEnd = entity.GetProperty(entity.GetPeriodEndPropertyName()!);
Expand Down Expand Up @@ -1404,6 +1408,8 @@ public virtual void Temporal_table_with_explicit_properties_mapped_to_the_period
Assert.Equal(7, entity.GetProperties().Count());

Assert.Equal("HistoryTable", entity.GetHistoryTableName());
Assert.Null(entity.GetHistoryTableSchema());
Assert.Equal("HistoryTable", entity.GetSchemaQualifiedHistoryTableName());

var periodStart = entity.GetProperty(entity.GetPeriodStartPropertyName()!);
var periodEnd = entity.GetProperty(entity.GetPeriodEndPropertyName()!);
Expand Down Expand Up @@ -1452,6 +1458,8 @@ public virtual void
Assert.Equal(9, entity.GetProperties().Count());

Assert.Equal("HistoryTable", entity.GetHistoryTableName());
Assert.Null(entity.GetHistoryTableSchema());
Assert.Equal("HistoryTable", entity.GetSchemaQualifiedHistoryTableName());

var periodStart = entity.GetProperty(entity.GetPeriodStartPropertyName()!);
var periodEnd = entity.GetProperty(entity.GetPeriodEndPropertyName()!);
Expand Down

0 comments on commit 6119066

Please sign in to comment.