60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
|
|
using BlueWest.Data;
|
|
using BlueWest.WebApi.EF.Model;
|
|
using MapTo;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BlueWest.WebApi.EF
|
|
{
|
|
/// <summary>
|
|
/// Context for accessing company data
|
|
/// </summary>
|
|
public sealed class CompanyDbContext : DbContext
|
|
{
|
|
/// <summary>
|
|
/// Companies.
|
|
/// </summary>
|
|
[EFAddMethods(typeof(CompanyCreate))]
|
|
[EFUpdateMethods(typeof(CompanyUpdate))]
|
|
|
|
public DbSet<Company> Companies { get; set; }
|
|
|
|
/// <summary>
|
|
/// Industries.
|
|
/// </summary>
|
|
[EFAddMethods(typeof(IndustryCreate))]
|
|
[EFUpdateMethods(typeof(IndustryUpdate))]
|
|
public DbSet<Industry> Industries { get; set; }
|
|
|
|
/// <summary>
|
|
/// Products.
|
|
/// </summary>
|
|
[EFAddMethods(typeof(ProductCreate))]
|
|
[EFUpdateMethods(typeof(IndustryUpdate))]
|
|
public DbSet<Product> Products { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// CompanyDbContext constructor.
|
|
/// </summary>
|
|
/// <param name="options"></param>
|
|
public CompanyDbContext(DbContextOptions<CompanyDbContext> options) : base(options)
|
|
{
|
|
Database.EnsureCreated();
|
|
}
|
|
|
|
/// <summary>
|
|
/// On model creating.
|
|
/// </summary>
|
|
/// <param name="modelBuilder">Builder model of the database</param>
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
modelBuilder.ConfigureCurrentDbModel();
|
|
}
|
|
|
|
}
|
|
}
|
|
|