When using TPH for storing entities class hierararchy, there can be case when some derived entities have the same property name. Column names in the database table then needs to be different for the two entities.
For example:
BaseClass class
- DerivedClassA
- DerivedClassB
Table BaseClass
- column Name
- column DerivedClassB_Name
This behavior is mentioned here: https://github.com/dotnet/efcore/issues/11046
GetColumnName() method returns "Name" for both cases.
To get the real column name, method GetColumnName must be called with parameter StoreObjectIdentifier.Table(tableName).
This returns "Name" for DerivedClassA entity and "DerivedClassB_Name" for DerivedClassB entity.
So, te code would be:
var entityType = _dataContext.Model.FindEntityType(typeof(DummyType));
string tableName = entityType.GetTableName();
var property = entityType?.GetProperty(nameof(DummyType.SecretId));
var columnName = property?.GetColumnName(StoreObjectIdentifier.Table(tableName));