25 lines
903 B
C#
25 lines
903 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.IO;
|
|
|
|
namespace FoodApp.Data
|
|
{
|
|
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
|
|
{
|
|
public ApplicationDbContext CreateDbContext(string[] args)
|
|
{
|
|
IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json")
|
|
.Build();
|
|
|
|
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
|
var connectionString = configuration.GetConnectionString("DefaultConnection");
|
|
builder.UseMySql(connectionString, new MySqlServerVersion(new Version(8, 0, 21)));
|
|
|
|
return new ApplicationDbContext(builder.Options);
|
|
}
|
|
}
|
|
}
|