-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using ContosoUniversity.Data.Entities; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ContosoUniversity.Data.DbContexts | ||
{ | ||
public class DbContextConfig | ||
{ | ||
public void ApplicationContextConfig(ModelBuilder modelBuilder, string schema = "") | ||
{ | ||
modelBuilder.Entity<Course>().ToTable("Course", schema); | ||
modelBuilder.Entity<Enrollment>().ToTable("Enrollment", schema); | ||
modelBuilder.Entity<Student>().ToTable("Student", schema); | ||
modelBuilder.Entity<Department>().ToTable("Department", schema); | ||
modelBuilder.Entity<Instructor>().ToTable("Instructor", schema); | ||
modelBuilder.Entity<OfficeAssignment>().ToTable("OfficeAssignment", schema); | ||
modelBuilder.Entity<CourseAssignment>().ToTable("CourseAssignment", schema); | ||
modelBuilder.Entity<Person>().ToTable("Person", schema); | ||
modelBuilder.Entity<CourseAssignment>().HasKey(c => new { c.CourseID, c.InstructorID }); | ||
} | ||
|
||
public void SecureApplicationContextConfig(ModelBuilder modelBuilder, string schema = "") | ||
{ | ||
modelBuilder.Entity<ApplicationUser>().ToTable("Users", schema); | ||
modelBuilder.Entity<IdentityRole>().ToTable("Role", schema); | ||
modelBuilder.Entity<IdentityUserClaim<string>>().ToTable("UserClaim", schema); | ||
modelBuilder.Entity<IdentityUserRole<string>>().ToTable("UserRole", schema); | ||
modelBuilder.Entity<IdentityUserLogin<string>>().ToTable("UserLogin", schema); | ||
modelBuilder.Entity<IdentityRoleClaim<string>>().ToTable("RoleClaim", schema); | ||
modelBuilder.Entity<IdentityUserToken<string>>().ToTable("UserToken", schema); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using ContosoUniversity.Data.DbContexts; | ||
using ContosoUniversity.Data.Entities; | ||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ContosoUniversity.Data | ||
{ | ||
public class WebContext : IdentityDbContext<ApplicationUser> | ||
{ | ||
public WebContext(DbContextOptions<WebContext> options) : base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Course> Courses { get; set; } | ||
public DbSet<Enrollment> Enrollments { get; set; } | ||
public DbSet<Student> Students { get; set; } | ||
public DbSet<Department> Departments { get; set; } | ||
public DbSet<Instructor> Instructors { get; set; } | ||
public DbSet<OfficeAssignment> OfficeAssignments { get; set; } | ||
public DbSet<CourseAssignment> CourseAssignments { get; set; } | ||
public DbSet<Person> People { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnModelCreating(modelBuilder); | ||
string schema = "Contoso"; | ||
if (OperatingSystem.IsMacOs()) | ||
{ | ||
schema = null; | ||
} | ||
|
||
var config = new DbContextConfig(); | ||
config.SecureApplicationContextConfig(modelBuilder, schema); | ||
config.ApplicationContextConfig(modelBuilder, schema); | ||
} | ||
} | ||
} |