EntityFrameworkCore.Cacheable icon indicating copy to clipboard operation
EntityFrameworkCore.Cacheable copied to clipboard

add extensions to DbContextOptionsBuilder<TContext>

Open alexandre-machado opened this issue 6 years ago • 1 comments

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 image

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;
        }

alexandre-machado avatar Nov 01 '19 01:11 alexandre-machado

alexandre-machado avatar Jan 04 '21 03:01 alexandre-machado