-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomDbContext.cs
More file actions
50 lines (44 loc) · 1.79 KB
/
CustomDbContext.cs
File metadata and controls
50 lines (44 loc) · 1.79 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
49
50
using Tutorial_AspNetMvc_IdentityCodeFirst.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Tutorial_AspNetMvc_IdentityCodeFirst
{
public class CustomDbContext : DbContext
{
public DbSet<Student> Students { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
public DbSet<Course> Courses { get; set; }
public CustomDbContext(DbContextOptions<CustomDbContext> options) : base(options)
{
#if ZEROMODE
//(1)Ensures that the database for the context does not exist.
//If it does not exist, no action is taken.
//If it does exist then the database is deleted.
Database.EnsureDeleted();
//(2) Ensures that the database for the context exists.
//If it exists, no action is taken.
//If it does not exist then the database and all its schema are created.
Database.EnsureCreated();
#endif
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
//optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=TestPostgreDB;Username=postgres;Password=7891");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}