Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using ProbeSeeker.Models;
- using System.IO;
- namespace DatabaseConnection.Models
- {
- public class DataContext : IdentityDbContext
- {
- public DataContext() :
- base()
- { }
- public DataContext(DbContextOptions<DataContext> options) :
- base(options)
- { }
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- var builder = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddJsonFile("appsettings.json");
- var configuration = builder.Build();
- optionsBuilder.UseSqlServer(configuration["ConnectionStrings:DefaultConnection"]);
- }
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- base.OnModelCreating(modelBuilder);
- modelBuilder.Entity<UserRoleModel>()
- .HasKey(ur => new { ur.UserId, ur.RoleId });
- modelBuilder.Entity<UserRoleModel>()
- .HasOne(ur => ur.User)
- .WithMany(u => u.UserRoles)
- .HasForeignKey(r => r.UserId);
- modelBuilder.Entity<UserRoleModel>()
- .HasOne(ur => ur.Role)
- .WithMany(r => r.UserRoles)
- .HasForeignKey(u => u.RoleId);
- }
- public DbSet<RoleModel> MyRoles { get; set; }
- public DbSet<UserRoleModel> MyUserRoles { get; set; }
- public DbSet<FacilityModel> Facilities { get; set; }
- public DbSet<SpecializationModel> Specializations { get; set; }
- public DbSet<TestModel> TestModels { get; set; }
- }
- public class TestModel
- {
- public int Id { get; set; }
- public int TestData { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement