persistence/DD.Persistence.Database.Postgres/DesignTimeDbContextFactory.cs
Olga Nemt d90b72b14e 1. Исправлены namespaces.
2. Добавлен проект DD.Persistence.App со всеми необходимыми настройками
2024-12-16 15:38:46 +05:00

31 lines
1.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Npgsql;
using DD.Persistence.Database.Model;
namespace DD.Persistence.Database.Postgres;
/// <summary>
/// Фабрика контекста для dotnet ef миграций
/// </summary>
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<PersistencePostgresContext>
{
public PersistencePostgresContext CreateDbContext(string[] args)
{
var connectionStringBuilder = new NpgsqlConnectionStringBuilder
{
Host = "localhost",
Database = "persistence",
Username = "postgres",
Password = "q",
PersistSecurityInfo = true
};
var connectionString = connectionStringBuilder.ToString();
var optionsBuilder = new DbContextOptionsBuilder<PersistencePostgresContext>();
optionsBuilder.UseNpgsql(connectionString);
var context = new PersistencePostgresContext(optionsBuilder.Options);
return context;
}
}