DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Documents/Db/DocumentDbContext.cs

38 lines
1.5 KiB
C#
Raw Normal View History

2023-08-31 18:00:51 -05:00
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.ComponentModel.DataAnnotations;
namespace DamageAssesment.Api.Documents.Db
{
public class DocumentDbContext : DbContext
{
2023-09-13 12:16:42 -05:00
private IConfiguration _Configuration { get; set; }
public DocumentDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
2023-08-31 18:00:51 -05:00
{
2023-09-13 12:16:42 -05:00
_Configuration = configuration;
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
// connect to sql server with connection string from app settings
options.UseSqlServer(_Configuration.GetConnectionString("DocumentConnection"));
2023-08-31 18:00:51 -05:00
}
public DbSet<Db.Document> Documents { get; set; }
public DbSet<Db.LinkType> LinkTypes { get; set; }
public DbSet<Db.DocumentsTranslation> DocumentsTranslations { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Document>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<LinkType>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<DocumentsTranslation>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
}
}
}