using BlueWest.Data;
using BlueWest.WebApi.EF.Model;
using MapTo;
using Microsoft.EntityFrameworkCore;
namespace BlueWest.WebApi.EF
{
///
/// Context for accessing company data
///
public sealed class CompanyDbContext : DbContext
{
///
/// Companies.
///
[EfAddMethods(typeof(CompanyCreate), typeof(CompanyUnique))]
[EfUpdateMethods(
updateType: typeof(CompanyUpdate),
returnType: typeof(CompanyUnique),
keyPropertyMemberName: "Id",
keyPropertyMemberType: typeof(int))
]
/*[EFUpdateMethods(typeof(int),
"Id",
typeof(CompanyUpdate),
typeof(CompanyUnique))]*/
public DbSet Companies { get; set; }
///
/// Industries.
///
[EfAddMethods(typeof(IndustryCreate), typeof(IndustryUnique))]
[EfUpdateMethods(
updateType: typeof(IndustryUpdate),
returnType: typeof(IndustryUnique),
keyPropertyMemberName: "Id",
keyPropertyMemberType: typeof(int))
]
public DbSet Industries { get; set; }
void TestExtensions()
{
// var (result, obj) = this.AddCountry(new CountryCreate());
}
///
/// Products.
///
/*
[EfAddMethods(typeof(ProductCreate))]
[EFUpdateMethods(typeof(int),
"Id",
typeof(ProductUpdate))]
*/
public DbSet Products { get; set; }
///
/// CompanyDbContext constructor.
///
///
public CompanyDbContext(DbContextOptions options) : base(options)
{
Database.EnsureCreated();
}
///
/// On model creating.
///
/// Builder model of the database
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.ConfigureCurrentDbModel();
}
}
}