49 lines
2.0 KiB
C#
49 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace DamageAssesment.Api.Questions.Db
|
|
{
|
|
public class QuestionDbContext : DbContext
|
|
{
|
|
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"));
|
|
}
|
|
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; }
|
|
public DbSet<Db.CategoryTranslation> CategoryTranslations { get; set; }
|
|
public QuestionDbContext(DbContextOptions options) : base(options)
|
|
{
|
|
|
|
}
|
|
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();
|
|
modelBuilder.Entity<CategoryTranslation>()
|
|
.Property(item => item.Id)
|
|
.ValueGeneratedOnAdd();
|
|
}
|
|
}
|
|
}
|