42 lines
1.3 KiB
C#
42 lines
1.3 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 string _connectionString;
|
|
|
|
public DaSaSoDbContextFactory()
|
|
{
|
|
|
|
}
|
|
public DaSaSoDbContextFactory(string connectionString)
|
|
{
|
|
_connectionString = connectionString;
|
|
}
|
|
|
|
public DaSaSoDbContext CreateDbContext()
|
|
{
|
|
var options = new DbContextOptionsBuilder<DaSaSoDbContext>();
|
|
//_connectionString = "Host = localhost; Database = dasaso; Username = kansan; Password = kansan";
|
|
options.UseNpgsql(_connectionString);
|
|
DaSaSoDbContext result = new DaSaSoDbContext(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;
|
|
}
|
|
}
|
|
}
|