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>
|
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-08-29 03:40:57 +03:00
|
|
|
[EfUpdateMethods(
|
|
|
|
updateType: typeof(CompanyUpdate),
|
|
|
|
returnType: typeof(CompanyUnique),
|
2022-08-29 19:30:24 +03:00
|
|
|
keyPropertyMemberName: nameof(Company.Id),
|
2022-08-29 03:40:57 +03:00
|
|
|
keyPropertyMemberType: typeof(int))
|
2022-08-28 21:39:40 +03:00
|
|
|
]
|
2022-08-29 03:40:57 +03:00
|
|
|
|
2022-08-27 06:19:30 +03:00
|
|
|
/*[EFUpdateMethods(typeof(int),
|
2022-08-24 19:56:51 +03:00
|
|
|
"Id",
|
|
|
|
typeof(CompanyUpdate),
|
2022-08-27 06:19:30 +03:00
|
|
|
typeof(CompanyUnique))]*/
|
2022-08-23 19:48:16 +03:00
|
|
|
|
2022-08-22 00:14:50 +03:00
|
|
|
public DbSet<Company> Companies { get; set; }
|
|
|
|
|
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-08-29 03:40:57 +03:00
|
|
|
[EfUpdateMethods(
|
|
|
|
updateType: typeof(IndustryUpdate),
|
|
|
|
returnType: typeof(IndustryUnique),
|
2022-08-29 19:30:24 +03:00
|
|
|
keyPropertyMemberName: nameof(Industry.Id),
|
2022-08-29 03:40:57 +03:00
|
|
|
keyPropertyMemberType: typeof(int))
|
|
|
|
]
|
2022-08-22 00:14:50 +03:00
|
|
|
|
2022-08-24 19:56:51 +03:00
|
|
|
public DbSet<Industry> Industries { get; set; }
|
|
|
|
|
|
|
|
void TestExtensions()
|
|
|
|
{
|
|
|
|
// var (result, obj) = this.AddCountry(new CountryCreate());
|
|
|
|
}
|
2022-08-22 02:51:45 +03:00
|
|
|
/// <summary>
|
2022-08-22 05:13:53 +03:00
|
|
|
/// Products.
|
2022-08-22 02:51:45 +03:00
|
|
|
/// </summary>
|
2022-08-24 19:56:51 +03:00
|
|
|
/*
|
|
|
|
[EfAddMethods(typeof(ProductCreate))]
|
|
|
|
[EFUpdateMethods(typeof(int),
|
|
|
|
"Id",
|
|
|
|
typeof(ProductUpdate))]
|
|
|
|
*/
|
|
|
|
|
2022-08-22 00:14:50 +03:00
|
|
|
public DbSet<Product> Products { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|