2022-08-22 00:14:50 +03:00
|
|
|
|
|
|
|
using BlueWest.Data;
|
2022-09-19 05:50:15 +03:00
|
|
|
using BlueWest.Domain.Model;
|
2022-09-06 01:17:47 +03:00
|
|
|
using BlueWest.EfMethods;
|
2022-08-22 00:14:50 +03:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
2022-09-19 05:50:15 +03:00
|
|
|
namespace BlueWest.Domain
|
2022-08-22 00:14:50 +03:00
|
|
|
{
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Context for accessing company data
|
|
|
|
/// </summary>
|
2022-09-06 00:42:45 +03:00
|
|
|
[EfGenerator]
|
2022-08-22 02:51:45 +03:00
|
|
|
public sealed class CompanyDbContext : DbContext
|
2022-08-22 00:14:50 +03:00
|
|
|
{
|
2022-09-06 00:42:45 +03:00
|
|
|
#region Companies
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
2022-08-22 05:13:53 +03:00
|
|
|
/// Companies.
|
2022-08-22 02:51:45 +03:00
|
|
|
/// </summary>
|
2022-08-24 19:56:51 +03:00
|
|
|
[EfAddMethods(typeof(CompanyCreate), typeof(CompanyUnique))]
|
2022-09-09 06:26:16 +03:00
|
|
|
[EfUpdateMethods(typeof(CompanyUpdate),returnType: typeof(CompanyUnique),nameof(Company.Id))]
|
2022-08-29 03:40:57 +03:00
|
|
|
|
2022-08-22 00:14:50 +03:00
|
|
|
public DbSet<Company> Companies { get; set; }
|
2022-09-06 00:42:45 +03:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Industries
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
2022-08-22 05:13:53 +03:00
|
|
|
/// Industries.
|
2022-08-22 02:51:45 +03:00
|
|
|
/// </summary>
|
2022-08-24 19:56:51 +03:00
|
|
|
[EfAddMethods(typeof(IndustryCreate), typeof(IndustryUnique))]
|
2022-09-06 01:37:52 +03:00
|
|
|
|
2022-08-29 03:40:57 +03:00
|
|
|
[EfUpdateMethods(
|
|
|
|
updateType: typeof(IndustryUpdate),
|
|
|
|
returnType: typeof(IndustryUnique),
|
2022-09-01 08:54:42 +03:00
|
|
|
keyPropertyMemberName: nameof(Industry.Id)
|
|
|
|
)
|
2022-08-29 03:40:57 +03:00
|
|
|
]
|
2022-08-22 00:14:50 +03:00
|
|
|
|
2022-08-24 19:56:51 +03:00
|
|
|
public DbSet<Industry> Industries { get; set; }
|
|
|
|
|
2022-09-06 00:42:45 +03:00
|
|
|
#endregion
|
|
|
|
|
2022-09-06 01:37:52 +03:00
|
|
|
#region Products
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Products
|
|
|
|
/// </summary>
|
2022-08-22 00:14:50 +03:00
|
|
|
|
2022-09-06 01:37:52 +03:00
|
|
|
[EfAddMethods(typeof(ProductCreate), typeof(ProductUnique))]
|
|
|
|
|
|
|
|
[EfUpdateMethods(
|
|
|
|
updateType: typeof(ProductUpdate),
|
|
|
|
returnType: typeof(ProductUnique),
|
|
|
|
keyPropertyMemberName: nameof(Product.Id)
|
|
|
|
)
|
|
|
|
]
|
2022-08-22 00:14:50 +03:00
|
|
|
|
2022-09-06 01:37:52 +03:00
|
|
|
public DbSet<Product> Products { get; set; }
|
|
|
|
#endregion
|
2022-08-22 00:14:50 +03:00
|
|
|
|
2022-09-06 01:37:52 +03:00
|
|
|
#region Initialization
|
|
|
|
|
2022-08-22 00:14:50 +03:00
|
|
|
/// <summary>
|
2022-08-22 05:13:53 +03:00
|
|
|
/// CompanyDbContext constructor.
|
2022-08-22 00:14:50 +03:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="options"></param>
|
|
|
|
public CompanyDbContext(DbContextOptions<CompanyDbContext> options) : base(options)
|
|
|
|
{
|
|
|
|
Database.EnsureCreated();
|
|
|
|
}
|
|
|
|
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
2022-08-22 05:13:53 +03:00
|
|
|
/// On model creating.
|
2022-08-22 02:51:45 +03:00
|
|
|
/// </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();
|
|
|
|
}
|
|
|
|
|
2022-09-06 01:37:52 +03:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
2022-08-22 00:14:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|