2023-08-15 22:52:30 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace DamageAssesment.Api.Locations.Db
|
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public class LocationDbContext : DbContext
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-08-18 16:14:41 -05:00
|
|
|
|
private IConfiguration _Configuration { get; set; }
|
|
|
|
|
public LocationDbContext(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-08-15 22:52:30 -05:00
|
|
|
|
}
|
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("LocationConnection"));
|
|
|
|
|
}
|
|
|
|
|
public DbSet<Db.Location> Locations { get; set; }
|
|
|
|
|
public DbSet<Db.Region> Regions { get; set; }
|
2023-08-15 22:52:30 -05:00
|
|
|
|
public LocationDbContext(DbContextOptions options) : base(options)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2023-09-13 00:28:24 -05:00
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
|
modelBuilder.Entity<Location>()
|
|
|
|
|
.Property(item => item.Id)
|
|
|
|
|
.ValueGeneratedOnAdd();
|
|
|
|
|
modelBuilder.Entity<Region>()
|
|
|
|
|
.Property(item => item.Id)
|
|
|
|
|
.ValueGeneratedOnAdd();
|
|
|
|
|
|
|
|
|
|
}
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|