Home:ALL Converter>What's the difference between GetColumnBaseName and GetColumnName in EF Core?

What's the difference between GetColumnBaseName and GetColumnName in EF Core?

Ask Time:2021-09-19T17:14:19         Author:JohnyL

Json Formatter

In order to retrieve database column name, there are two methods: GetColumnBaseName and GetColumnName.

  1. What's the difference between them?
  2. Why GetColumnName requires StoreObjectIdentifier with custom values for table name? Doesn't Metadata know the table based on its parent PropertyEntry property?
using var db = new TestContext();
var customer = await db.Customers.FirstAsync(c => c.Id == 1);
customer.Address = "Jon";
var entry = db.Entry(customer);
var modifiedProperty = entry.Properties.First( p => p.IsModified );

// Using "GetColumnName"
var baseName = modifiedProperty.Metadata.GetColumnBaseName();

// Using "GetColumnName"
// Doesn't Metadata know the table?
var id = StoreObjectIdentifier.Table("customer", schema: "dbo");
var columnName = modifiedProperty.Metadata.GetColumnName(id);

Author:JohnyL,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69241886/whats-the-difference-between-getcolumnbasename-and-getcolumnname-in-ef-core
yy