Efcore: Question: why `GetColumnName` extension method is obsolete

Created on 13 Nov 2020  路  3Comments  路  Source: dotnet/efcore

Ask a question

In ef core 3.1, I use propertyEntry.Metadata.GetColumnName extension method to get the mapped column name,

while upgrade to ef core 5.0, I get a warning like Use the overload that takes a StoreObjectIdentifier.

I'd tried to add an extension method like follow:

public static string GetColumnName(this PropertyEntry propertyEntry)
{
    var storeObjectId =
                StoreObjectIdentifier.Create(propertyEntry.Metadata.DeclaringEntityType, StoreObjectType.Table);
    return propertyEntry.Metadata.GetColumnName(storeObjectId.GetValueOrDefault());
}

Seemed it works for my scene, but not sure whether it's the best practice or not

Could anyone please help on this, thanks in advance

Include provider and version information

EF Core version: 5.0.0
Database provider: (Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (.NET 5.0)
IDE: (Visual Studio 2019 16.8)

closed-question customer-reported

All 3 comments

@WeihanLi The method is obsolete because it will not always give the correct answer for newer models. For EF Core 5.0, this only means models that have TPT inheritance mapping, but as we add more features there will be more cases where the method will give the wrong answer.

If you have a model for 3.1 and you haven't changed it to use TPT, then you should be okay calling the implementation above in 5.0.

Thanks @ajcvickers

@ajcvickers I feel like this should be added to the list of breaking changes or documented somewhere else with a migration guide. I couldn't figure out that I had to use StoreObjectIdentifier.Create, at first I was just trying to find this 'identifier' in properties or methods in various metadata. I only found out how to create a StoreObjectIdentifier when browsing this repository to see how GetColumnName is now used.

Was this page helpful?
0 / 5 - 0 ratings