29 lines
997 B
C#
29 lines
997 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace DamageAssesment.Api.Answers.Db
|
|
{
|
|
public class AnswerDbContext:DbContext
|
|
{
|
|
private IConfiguration _Configuration { get; set; }
|
|
public AnswerDbContext(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("AnswerConnection"));
|
|
}
|
|
public DbSet<Db.Answer> Answers { get; set; }
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
modelBuilder.Entity<Answer>()
|
|
.Property(item => item.Id)
|
|
.ValueGeneratedOnAdd();
|
|
}
|
|
}
|
|
|
|
}
|