We need to apply generic convention by implementing IModelFinalizingConvention interface and adding new class to overrided DbContext function ConfigureConventions but when run add migration command nothing happened which means the convention is not applied on our decimal properties. did we miss any config or there is another way to apply generic convention for all entities all decimal properties.
public class DecimalPrecisionConvention : IModelFinalizingConvention
{
public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext\<IConventionModelBuilder> context)
{
foreach (var property in modelBuilder.Metadata.GetEntityTypes()
.SelectMany(entityType => entityType.GetDeclaredProperties()
.Where(property => property.ClrType == typeof(decimal))))
{
property.Builder.HasColumnType("decimal(18,6)");
}
}
}
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.Conventions.Add(\_ => new DecimalPrecisionConvention());
}