using BlueWest.Data;
using BlueWest.WebApi.EF.Model;
using MapTo;
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(
updateType: typeof(CompanyUpdate),
returnType: typeof(CompanyUnique),
keyPropertyMemberName: 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
public DbSet Products { get; set; }
///
/// 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();
}
}
}