DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Questions/Db/QuestionDbContext.cs

49 lines
2.0 KiB
C#
Raw Permalink Normal View History

2023-08-15 22:52:30 -05:00
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
namespace DamageAssesment.Api.Questions.Db
{
public class QuestionDbContext : DbContext
{
2023-08-18 16:14:41 -05:00
private IConfiguration _Configuration { get; set; }
public QuestionDbContext(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("QuestionConnection"));
}
2023-08-15 22:52:30 -05:00
public DbSet<Db.Question> Questions { get; set; }
public DbSet<Db.QuestionType> QuestionTypes { get; set; }
public DbSet<Db.QuestionsTranslation> QuestionsTranslations { get; set; }
public DbSet<Db.QuestionCategory> QuestionCategories { get; set; }
2023-09-08 14:40:06 -05:00
public DbSet<Db.CategoryTranslation> CategoryTranslations { get; set; }
2023-08-15 22:52:30 -05:00
public QuestionDbContext(DbContextOptions options) : base(options)
{
}
2023-08-25 17:24:46 -05:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Question>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<QuestionType>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<QuestionsTranslation>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<QuestionCategory>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
2023-09-08 14:40:06 -05:00
modelBuilder.Entity<CategoryTranslation>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
2023-08-25 17:24:46 -05:00
}
2023-08-15 22:52:30 -05:00
}
}