I want to set decimal precision and scale for all decimal properties in my model. I know one of the way to do this in EF Core 6 is to override ConfigureConventions,
protected override void ConfigureConventions(
ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.Properties<decimal>()
.HavePrecision(18, 6);
}
However, I do not have access to underlying DBContext to override or subclass it. I am using it as part of nuget package.
I have access to pass only DbContextOptionsBuilder in my application's Startup class to some method from underlying framework method which accepts parameter of type DbContextOptionsBuilder.
The underlying framework adds DbContext using AddDbContextPool method and passes DbContextOptionsBuilder received as a parameter. It is added to IServiceCollection.
public static void ConfigureMyAppServices(IServiceCollection services, Action<DbContextOptionsBuilder> configuration)
{
services.AddDbContextPool<MyAppDbContext>(configuration);
}
Here MyAppDbContext inherits from DbContext.
Is there a way to plugin conventions for the entire model using DbContextOptionsBuilder object.