DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkDbContext.cs
2023-09-26 12:40:55 -04:00

46 lines
1.9 KiB
C#

using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.ComponentModel.DataAnnotations;
namespace DamageAssesment.Api.DocuLinks.Db
{
public class DoculinkDbContext : DbContext
{
private IConfiguration _Configuration { get; set; }
public DoculinkDbContext(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("DoculinConnection"));
}
public DbSet<Db.Doculink> Documents { get; set; }
public DbSet<Db.LinkType> LinkTypes { get; set; }
public DbSet<Db.DoculinkTranslation> DocumentsTranslations { get; set; }
public DbSet<Db.LinksTranslation> LinksTranslations { get; set; }
public DbSet<Db.DoculinkAttachments> DoclinksAttachments { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Doculink>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<LinkType>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<DoculinkTranslation>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<LinksTranslation>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<DoculinkAttachments>()
.Property(item => item.Id)
.ValueGeneratedOnAdd();
}
}
}