dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.76k stars 3.18k forks source link

Add GetSchemaQualifiedHistoryTableName method to SqlServerEntityTypeExtensions #35018

Open IanKemp opened 5 days ago

IanKemp commented 5 days ago

RelationalEntityTypeExtensions has the GetSchemaQualifiedTableName method, a complementing method should be added for temporal tables on SqlServerEntityTypeExtensions:

public static string? GetSchemaQualifiedHistoryTableName(this IReadOnlyEntityType entityType)
{
    var tableName = entityType.GetHistoryTableName();
    if (tableName == null)
    {
        return null;
    }

    var schema = entityType.GetHistoryTableSchema();
    return (string.IsNullOrEmpty(schema) ? string.Empty : schema + ".") + tableName;
}
TomLincoln066 commented 3 days ago

Hello~ @IanKemp @maumar I'm quite new here. If it's ok I'd like to start investigating this issue and see how far I can get. Thank you!

TomLincoln066 commented 3 days ago

I’ve just reviewed the idea of adding GetSchemaQualifiedHistoryTableName to SqlServerEntityTypeExtensions (from Ian) and explored similar methods in the codebase. It seems this would complement GetSchemaQualifiedTableName for temporal tables. From what I understand, we might need to use (or add) GetHistoryTableName and GetHistoryTableSchema for this to work correctly. Feel free to correct me if I'm wrong.

However, I wonder do you guys know whether anyone in this repo would double confirm if this is on the right track? If there are any specific conventions or testing guidelines for temporal tables, I’d appreciate the advice as well. Thanks!