Files
DaSaSo/DaSaSo.EntityFramework/DaSaSoDbContextFactory.cs
2021-09-30 16:27:28 +02:00

51 lines
1.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DaSaSo.EntityFramework
{
public class DaSaSoDbContextFactory : IDesignTimeDbContextFactory<DaSaSoDbContext>
{
private readonly Action<DbContextOptionsBuilder> _configureDbContext;
public DaSaSoDbContextFactory() { }
public DaSaSoDbContextFactory(Action<DbContextOptionsBuilder> configureDbContext)
{
_configureDbContext = configureDbContext;
}
public DaSaSoDbContext CreateDbContext()
{
DbContextOptionsBuilder<DaSaSoDbContext>? options = new();
_configureDbContext(options);
//_connectionString = "Host = localhost; Database = dasaso; Username = kansan; Password = kansan";
//options.UseNpgsql(_connectionString);
//DaSaSoDbContext result = new DaSaSoDbContext(options.Options);
return new DaSaSoDbContext(options.Options);
}
public DaSaSoDbContext CreateDbContext(string[] args)
{
var options = new DbContextOptionsBuilder<DaSaSoDbContext>();
options.UseNpgsql("Host = localhost; Database = dasaso; Username = kansan; Password = kansan");
DaSaSoDbContext result = new(options.Options);
return result;
}
/*
public DaSaSoDbContext CreateDbContext(string[]? args = null)
{
var options = new DbContextOptionsBuilder<DaSaSoDbContext>();
options.UseNpgsql("Host = localhost; Database = dasaso; Username = kansan; Password = kansan");
DaSaSoDbContext result = new DaSaSoDbContext(options.Options);
return result;
}
*/
}
}