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

50 lines
1.3 KiB
C#
Raw Normal View History

2022-08-13 06:35:36 +03:00
using BlueWest.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace BlueWest.WebApi.MySQL;
2022-08-13 20:15:43 +03:00
/// <summary>
2022-08-19 02:02:57 +03:00
/// Countries and Currencies
2022-08-13 20:15:43 +03:00
/// </summary>
2022-08-19 06:22:55 +03:00
public class CountryDbContext : DbContext
2022-08-13 06:35:36 +03:00
{
public DbSet<Country> Countries { get; set; }
public DbSet<Currency> Currencies { get; set; }
2022-08-19 06:18:50 +03:00
public DbSet<User> Users { get; set; }
2022-08-13 06:35:36 +03:00
public IConfiguration Configuration;
2022-08-13 20:15:43 +03:00
/// <summary>
/// Options to be injected in the app
/// </summary>
/// <param name="options"></param>
2022-08-19 06:22:55 +03:00
public CountryDbContext(DbContextOptions<CountryDbContext> options) : base(options)
2022-08-13 06:35:36 +03:00
{
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
/*optionsBuilder.UseMySql(
Configuration.GetConnectionString("LocalMySQL"),
new MySqlServerVersion(new Version(8, 0, 11))
);*/
}
2022-08-13 20:15:43 +03:00
/// <summary>
/// The country number is the primary key
/// The currency code is the primary key
/// </summary>
/// <param name="modelBuilder"></param>
2022-08-13 06:35:36 +03:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
2022-08-13 20:15:43 +03:00
base.OnModelCreating(modelBuilder);
2022-08-19 06:18:50 +03:00
modelBuilder.ProjectDatabaseModel();
2022-08-13 06:35:36 +03:00
}
}