CodeLiturgy.Dashboard/BlueWest.Api/MySQL/CountryDbContext.cs

50 lines
1.3 KiB
C#

using BlueWest.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace BlueWest.WebApi.MySQL;
/// <summary>
/// Countries and Currencies
/// </summary>
public class CountryDbContext : DbContext
{
public DbSet<Country> Countries { get; set; }
public DbSet<Currency> Currencies { get; set; }
public DbSet<User> Users { get; set; }
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();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
/*optionsBuilder.UseMySql(
Configuration.GetConnectionString("LocalMySQL"),
new MySqlServerVersion(new Version(8, 0, 11))
);*/
}
/// <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.ProjectDatabaseModel();
}
}