85 lines
2.3 KiB
C#
85 lines
2.3 KiB
C#
|
|
using BlueWest.Data;
|
|
using BlueWest.WebApi.EF.Model;
|
|
using MapTo;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BlueWest.WebApi.EF
|
|
{
|
|
/// <summary>
|
|
/// Context for accessing company data
|
|
/// </summary>
|
|
public sealed class CompanyDbContext : DbContext
|
|
{
|
|
/// <summary>
|
|
/// Companies.
|
|
/// </summary>
|
|
[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<Company> Companies { get; set; }
|
|
|
|
/// <summary>
|
|
/// Industries.
|
|
/// </summary>
|
|
[EfAddMethods(typeof(IndustryCreate), typeof(IndustryUnique))]
|
|
[EfUpdateMethods(
|
|
updateType: typeof(IndustryUpdate),
|
|
returnType: typeof(IndustryUnique),
|
|
keyPropertyMemberName: "Id",
|
|
keyPropertyMemberType: typeof(int))
|
|
]
|
|
|
|
public DbSet<Industry> Industries { get; set; }
|
|
|
|
void TestExtensions()
|
|
{
|
|
// var (result, obj) = this.AddCountry(new CountryCreate());
|
|
}
|
|
/// <summary>
|
|
/// Products.
|
|
/// </summary>
|
|
/*
|
|
[EfAddMethods(typeof(ProductCreate))]
|
|
[EFUpdateMethods(typeof(int),
|
|
"Id",
|
|
typeof(ProductUpdate))]
|
|
*/
|
|
|
|
public DbSet<Product> Products { get; set; }
|
|
|
|
|
|
|
|
/// <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();
|
|
}
|
|
|
|
}
|
|
}
|
|
|