CodeLiturgy.Dashboard/BlueWest.Domain/CompanyDbContext.cs

88 lines
2.2 KiB
C#

using BlueWest.Data;
using BlueWest.Domain.Model;
using BlueWest.EfMethods;
using Microsoft.EntityFrameworkCore;
namespace BlueWest.Domain
{
/// <summary>
/// Context for accessing company data
/// </summary>
[EfGenerator]
public sealed class CompanyDbContext : DbContext
{
#region Companies
/// <summary>
/// Companies.
/// </summary>
[EfAddMethods(typeof(CompanyCreate), typeof(CompanyUnique))]
[EfUpdateMethods(typeof(CompanyUpdate),returnType: typeof(CompanyUnique),nameof(Company.Id))]
public DbSet<Company> Companies { get; set; }
#endregion
#region Industries
/// <summary>
/// Industries.
/// </summary>
[EfAddMethods(typeof(IndustryCreate), typeof(IndustryUnique))]
[EfUpdateMethods(
updateType: typeof(IndustryUpdate),
returnType: typeof(IndustryUnique),
keyPropertyMemberName: nameof(Industry.Id)
)
]
public DbSet<Industry> Industries { get; set; }
#endregion
#region Products
/// <summary>
/// Products
/// </summary>
[EfAddMethods(typeof(ProductCreate), typeof(ProductUnique))]
[EfUpdateMethods(
updateType: typeof(ProductUpdate),
returnType: typeof(ProductUnique),
keyPropertyMemberName: nameof(Product.Id)
)
]
public DbSet<Product> Products { get; set; }
#endregion
#region Initialization
/// <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();
}
#endregion
}
}