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

Add GetSchemaQualifiedHistoryTableName method to SqlServerEntityTypeExtensions #35368

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -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