I have such EntityTypeConfiguration class.
public class DummyTypeConfiguration : IEntityTypeConfiguration<DummyType>
{
public void Configure(EntityTypeBuilder<DummyType> builder)
{
builder.HasNoKey();
builder.Property(p => p.SecretId).HasColumnName("secretID");
...
}
}
I want to retrieve the column name: "secretID" by using the property DummyType.SecretId as such:
var columnName = ...(DummyType.SecretId);
CodePudding user response:
EF Core 6: That can be done using the code below:
var entityType = _dataContext.Model.FindEntityType(typeof(DummyType));
var property = entityType?.GetProperty(nameof(DummyType.SecretId));
var columnName = property?.GetColumnName();
The _dataContext
variable represents object instance of DbContext
class.