53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using BlueWest.Data;
|
|
using BlueWest.WebApi.EF.Model;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace BlueWest.WebApi.EF
|
|
{
|
|
|
|
/// <summary>
|
|
/// Countries and Currencies
|
|
/// </summary>
|
|
public sealed class CountryDbContext : DbContext
|
|
{
|
|
|
|
/// <summary>
|
|
/// Countries Database Table
|
|
/// </summary>
|
|
public DbSet<Country> Countries { get; set; }
|
|
|
|
/// <summary>
|
|
/// Currencies Database Table
|
|
/// </summary>
|
|
public DbSet<Currency> Currencies { get; set; }
|
|
|
|
/// <summary>
|
|
/// App Configuration
|
|
/// </summary>
|
|
public IConfiguration Configuration;
|
|
|
|
|
|
/// <summary>
|
|
/// Options to be injected in the app
|
|
/// </summary>
|
|
/// <param name="options"></param>
|
|
public CountryDbContext(DbContextOptions<CountryDbContext> options) : base(options)
|
|
{
|
|
Database.EnsureCreated();
|
|
}
|
|
|
|
/// <summary>
|
|
/// The country number is the primary key
|
|
/// The currency code is the primary key
|
|
/// </summary>
|
|
/// <param name="modelBuilder"></param>
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
modelBuilder.ConfigureCurrentDbModel();
|
|
}
|
|
|
|
}
|
|
}
|