EntityFrameworkCore.Cacheable
EntityFrameworkCore.Cacheable copied to clipboard
add extensions to DbContextOptionsBuilder<TContext>
In some scenarios, we need to write this:
var dbContextOptions = new DbContextOptionsBuilder<CoreDbContext>()
.UseMySql(_connection);
dbContextOptions.UseSecondLevelCache();
_options = dbContextOptions.Options;
instead this:
_options = new DbContextOptionsBuilder<CoreDbContext>()
.UseMySql(_connection)
.UseSecondLevelCache().Options;
because we need the DbContextOptions<TDbContext> and it is not possible

or in custom DbContextOptions creation:
private static DbContextOptions BuildContextOptions(IResolver resolver, string connectionName)
{
var optionsBuilder = new DbContextOptionsBuilder<CoreDbContext>();
var connectionString = resolver.Resolve<IAppConfig>().GetConnectionString(connectionName);
optionsBuilder
.UseMySql(connectionString)
.UseSecondLevelCache();
return optionsBuilder.Options;
}
✋