93 lines
2.3 KiB
C#
93 lines
2.3 KiB
C#
|
|
using BlueWest.Data;
|
|
using BlueWest.WebApi.EF.Model;
|
|
using BlueWest.EfMethods;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BlueWest.WebApi.EF
|
|
{
|
|
/// <summary>
|
|
/// Context for accessing company data
|
|
/// </summary>
|
|
[EfGenerator]
|
|
public sealed class CompanyDbContext : DbContext
|
|
{
|
|
#region Companies
|
|
/// <summary>
|
|
/// Companies.
|
|
/// </summary>
|
|
[EfAddMethods(typeof(CompanyCreate), typeof(CompanyUnique))]
|
|
|
|
[EfUpdateMethods(
|
|
updateType: typeof(CompanyUpdate),
|
|
returnType: typeof(CompanyUnique),
|
|
keyPropertyMemberName: 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
|
|
|
|
|
|
}
|
|
}
|
|
|