forked from Nethereum/Nethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesignTimeMudPostgresStoreRecordsDbContextFactory.cs
More file actions
33 lines (26 loc) · 1.27 KB
/
Copy pathDesignTimeMudPostgresStoreRecordsDbContextFactory.cs
File metadata and controls
33 lines (26 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Nethereum.Mud.Repositories.Postgres;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace NethereumMudLogProcessing
{
public class DesignTimeMudPostgresStoreRecordsDbContextFactory : IDesignTimeDbContextFactory<MudPostgresStoreRecordsDbContext>
{
public MudPostgresStoreRecordsDbContext CreateDbContext(string[] args)
{
// Load the configuration from the appsettings.json or other sources
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
// Get the connection string from the configuration
var connectionString = configuration.GetConnectionString("PostgresConnection");
// Configure the DbContext options
var optionsBuilder = new DbContextOptionsBuilder<MudPostgresStoreRecordsDbContext>();
optionsBuilder.UseNpgsql(connectionString, b => b.MigrationsAssembly("NethereumMudLogProcessing"))
.UseLowerCaseNamingConvention();
return new MudPostgresStoreRecordsDbContext(optionsBuilder.Options
);
}
}
}