DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Answers/Db/AnswerDbContext.cs

29 lines
997 B
C#
Raw Normal View History

2023-08-15 22:52:30 -05:00
using Microsoft.EntityFrameworkCore;
2023-08-18 16:14:41 -05:00
using Microsoft.Extensions.Configuration;
2023-08-15 22:52:30 -05:00
namespace DamageAssesment.Api.Answers.Db
{
public class AnswerDbContext:DbContext
{
2023-08-18 16:14:41 -05:00
private IConfiguration _Configuration { get; set; }
public AnswerDbContext(DbContextOptions options,IConfiguration configuration):base(options)
{
_Configuration= configuration;
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
2023-08-15 22:52:30 -05:00
{
2023-08-18 16:14:41 -05:00
// connect to sql server with connection string from app settings
options.UseSqlServer(_Configuration.GetConnectionString("AnswerConnection"));
2023-08-15 22:52:30 -05:00
}
public DbSet<Db.Answer> Answers { get; set; }
2023-08-25 17:24:46 -05:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Answer>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
}
2023-08-15 22:52:30 -05:00
}
}