DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/SurveysDbContext.cs

34 lines
1.1 KiB
C#
Raw Normal View History

2023-08-15 22:52:30 -05:00
using Microsoft.EntityFrameworkCore;
namespace DamageAssesment.Api.Surveys.Db
{
public class SurveysDbContext : DbContext
2023-08-15 22:52:30 -05:00
{
2023-08-18 16:14:41 -05:00
private IConfiguration _Configuration { get; set; }
public SurveysDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
2023-08-15 22:52:30 -05:00
{
2023-08-18 16:14:41 -05:00
_Configuration = configuration;
}
2023-09-13 12:16:42 -05:00
public DbSet<Db.Survey> Surveys { get; set; }
public DbSet<Db.SurveyTranslation> SurveysTranslation { get; set; }
2023-08-18 16:14:41 -05:00
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
// connect to sql server with connection string from app settings
options.UseSqlServer(_Configuration.GetConnectionString("SurveyConnection"));
2023-08-15 22:52:30 -05:00
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Survey>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<SurveyTranslation>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
}
2023-08-15 22:52:30 -05:00
}
}