You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
942 B
30 lines
942 B
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
|
|
namespace Kynareth.Models;
|
|
|
|
public class KynarethDbContextFactory : IDesignTimeDbContextFactory<KynarethDbContext>
|
|
{
|
|
public KynarethDbContext CreateDbContext(ILoggerFactory? loggerFactory, IConfiguration config)
|
|
{
|
|
var connStr = config.GetConnectionString("Database");
|
|
|
|
var serverVersion = ServerVersion.AutoDetect(connStr);
|
|
|
|
var optionsBuilder = new DbContextOptionsBuilder<KynarethDbContext>()
|
|
.UseLoggerFactory(loggerFactory)
|
|
.UseMySql(connStr, serverVersion, x => x.EnableRetryOnFailure())
|
|
.UseLazyLoadingProxies();
|
|
|
|
return new KynarethDbContext(optionsBuilder.Options);
|
|
}
|
|
|
|
public KynarethDbContext CreateDbContext(string[] args = null) {
|
|
var config = new ConfigurationBuilder ()
|
|
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
|
.AddJsonFile("appsettings.json")
|
|
.Build();
|
|
|
|
return CreateDbContext(null, config);
|
|
}
|
|
} |