DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/SurveysDbContext.cs
2023-09-13 13:16:42 -04:00

34 lines
1.1 KiB
C#

using Microsoft.EntityFrameworkCore;
namespace DamageAssesment.Api.Surveys.Db
{
public class SurveysDbContext : DbContext
{
private IConfiguration _Configuration { get; set; }
public SurveysDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
{
_Configuration = configuration;
}
public DbSet<Db.Survey> Surveys { get; set; }
public DbSet<Db.SurveyTranslation> SurveysTranslation { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
// connect to sql server with connection string from app settings
options.UseSqlServer(_Configuration.GetConnectionString("SurveyConnection"));
}
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();
}
}
}