using BlueWest.Data; using BlueWest.WebApi.EF.Model; using BlueWest.EfMethods; using Microsoft.EntityFrameworkCore; namespace BlueWest.WebApi.EF { /// /// Context for accessing company data /// [EfGenerator] public sealed class CompanyDbContext : DbContext { #region Companies /// /// Companies. /// [EfAddMethods(typeof(CompanyCreate), typeof(CompanyUnique))] [EfUpdateMethods(typeof(CompanyUpdate),returnType: typeof(CompanyUnique),nameof(Company.Id))] public DbSet Companies { get; set; } #endregion #region Industries /// /// Industries. /// [EfAddMethods(typeof(IndustryCreate), typeof(IndustryUnique))] [EfUpdateMethods( updateType: typeof(IndustryUpdate), returnType: typeof(IndustryUnique), keyPropertyMemberName: nameof(Industry.Id) ) ] public DbSet Industries { get; set; } #endregion #region Products /// /// Products /// [EfAddMethods(typeof(ProductCreate), typeof(ProductUnique))] [EfUpdateMethods( updateType: typeof(ProductUpdate), returnType: typeof(ProductUnique), keyPropertyMemberName: nameof(Product.Id) ) ] public DbSet Products { get; set; } #endregion #region Initialization /// /// CompanyDbContext constructor. /// /// public CompanyDbContext(DbContextOptions options) : base(options) { Database.EnsureCreated(); } /// /// On model creating. /// /// Builder model of the database protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.ConfigureCurrentDbModel(); } #endregion } }