-
Notifications
You must be signed in to change notification settings - Fork 1
/
DatabaseContext.cs
39 lines (30 loc) · 1.13 KB
/
DatabaseContext.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
39
using DatabaseAccessLayer.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace DatabaseAccessLayer
{
public class DatabaseContext : DbContext
{
private readonly IConfiguration config;
public DbSet<UserModel> Users { get; private set; }
public DbSet<PointsModel> Points { get; private set; }
public DbSet<PointsLogModel> PointsLog { get; private set; }
public DatabaseContext(IConfiguration config)
{
this.config = config;
// TODO: Remove in production
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = config.GetConnectionString("postgres");
optionsBuilder.UseNpgsql(connectionString);
if (connectionString == null || connectionString == "")
{
connectionString = config.GetConnectionString("mysql");
optionsBuilder.UseMySql(connectionString);
}
base.OnConfiguring(optionsBuilder);
}
}
}