-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestContext.cs
38 lines (32 loc) · 1.43 KB
/
TestContext.cs
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
33
34
35
36
37
38
using CUSTIS.NetCore.EF.MigrationGenerationExtensions.PostgreSQL;
using CUSTIS.NetCore.EF.MigrationGenerationExtensions.SqlObjects;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace TestDataAccessLayer
{
public class TestContext : DbContext
{
public TestContext(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasDefaultSchema("migr_ext_tests");
modelBuilder.ApplyConfigurationsFromAssembly(typeof(Class1Configuration).Assembly);
// Add SqlObject directly
const string Sql = "create or replace view migr_ext_tests.v_view_10 as select * from migr_ext_tests.my_table;";
modelBuilder.AddSqlObjects(new SqlObject(Name: "v_view_10", SqlCode: Sql) { Order = 10 });
// Add all embedded resources, placed in assembly's "Sql" folder
// Only *.sql resources are added
modelBuilder.AddSqlObjects(assembly: typeof(Class1).Assembly, folder: "Sql");
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var builder = new ConfigurationBuilder()
.AddUserSecrets<TestContext>();
var cfg = builder.Build();
optionsBuilder.UseNpgsql(cfg["conn"]);
}
}
}