2022-08-22 00:14:50 +03:00
|
|
|
|
|
|
|
using BlueWest.Data;
|
|
|
|
using BlueWest.WebApi.EF.Model;
|
|
|
|
using MapTo;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
namespace BlueWest.WebApi.EF
|
|
|
|
{
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Context for accessing company data
|
|
|
|
/// </summary>
|
|
|
|
public sealed class CompanyDbContext : DbContext
|
2022-08-22 00:14:50 +03:00
|
|
|
{
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Db set of Companies
|
|
|
|
/// </summary>
|
2022-08-22 00:14:50 +03:00
|
|
|
public DbSet<Company> Companies { get; set; }
|
|
|
|
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Db set of Industries.
|
|
|
|
/// </summary>
|
2022-08-22 00:14:50 +03:00
|
|
|
public DbSet<Industry> Industries { get; set; }
|
|
|
|
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Db set of Products.
|
|
|
|
/// </summary>
|
2022-08-22 00:14:50 +03:00
|
|
|
public DbSet<Product> Products { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Options to be injected in the app
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="options"></param>
|
|
|
|
public CompanyDbContext(DbContextOptions<CompanyDbContext> options) : base(options)
|
|
|
|
{
|
|
|
|
Database.EnsureCreated();
|
|
|
|
}
|
|
|
|
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// On database model creating
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="modelBuilder">Builder model of the database</param>
|
2022-08-22 00:14:50 +03:00
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
{
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.ConfigureCurrentDbModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|