DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.UsersAccess/Db/UsersAccessDbContext.cs

40 lines
1.3 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace DamageAssesment.Api.UsersAccess.Db
{
public class UsersAccessDbContext : DbContext
{
public DbSet<Db.User> Users { get; set; }
public DbSet<Db.Role> Roles { get; set; }
public DbSet<Db.Token> Tokens { get; set; }
private IConfiguration _Configuration { get; set; }
public UsersAccessDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
{
_Configuration = configuration;
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
// connect to sql server with connection string from app settings
options.UseSqlServer(_Configuration.GetConnectionString("UsersAccessConnection"));
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<User>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<Role>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<Token>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
}
}
}