DemO/DEMO/Data/AppDbContextFactory.cs

20 lines
830 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// это нужно чтоб миграции знали как подключиться к базе
using Microsoft.EntityFrameworkCore; // работа с базой
using Microsoft.EntityFrameworkCore.Design; // для миграций
namespace DEMO.Data;
public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext> // фабрика для создания базы
{
// создаю базу (простой файл sqlite)
public AppDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>(); // настройки
// файл базы лежит рядом
optionsBuilder.UseSqlite("Data Source=DemoDB.db");
return new AppDbContext(optionsBuilder.Options); // отдаю готовую базу
}
}