-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathCsharpDbContext.cs
More file actions
48 lines (41 loc) · 1.51 KB
/
CsharpDbContext.cs
File metadata and controls
48 lines (41 loc) · 1.51 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Text;
using Microsoft.EntityFrameworkCore;
namespace DbModel
{
public class CsharpDbContext : DbContext
{
private readonly string _dbSystem;
private readonly string _connectionString;
public CsharpDbContext(DbContextOptions options) : base(options) { }
public CsharpDbContext(string dbSystem, string connectionString) : base()
{
_dbSystem = dbSystem;
_connectionString = connectionString;
}
public DbSet<CsharpAstNode> CsharpAstNodes { get; set; }
public DbSet<CsharpNamespace> CsharpNamespaces { get; set; }
public DbSet<CsharpClass> CsharpClasses { get; set; }
public DbSet<CsharpMethod> CsharpMethods { get; set; }
public DbSet<CsharpVariable> CsharpVariables { get; set; }
public DbSet<CsharpStruct> CsharpStructs { get; set; }
public DbSet<CsharpEnum> CsharpEnums { get; set; }
public DbSet<CsharpEnumMember> CsharpEnumMembers { get; set; }
public DbSet<CsharpEtcEntity> CsharpEtcEntitys { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
switch(_dbSystem)
{
case "pgsql":
optionsBuilder.UseNpgsql(_connectionString,
x => x.MigrationsAssembly("pgsqlMigrations"));
break;
case "sqlite":
optionsBuilder.UseSqlite(_connectionString,
x => x.MigrationsAssembly("sqliteMigrations"));
break;
default:
break;
}
}
}
}