using BlueWest.Data; using BlueWest.WebApi.EF.Model; using MapTo; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; namespace BlueWest.WebApi.EF { /// /// Countries and Currencies /// public sealed class CountryDbContext : DbContext { /// /// Countries Database Table /// [EfGetOne( returnType: typeof(CountryUnique), keyMembernameof: nameof(Country.Id)) ] [EfAddEntityToList( listEntityType: typeof(Currency), listEntityCreateType: typeof(CurrencyCreate), listEntityReturnType: typeof(CurrencyUnique), keyMembernameof: nameof(Country.Id)) ] [EfAddMethods( createType: typeof(CountryCreate), returnType: typeof(CountryUnique)) ] [EfUpdateMethods( updateType: typeof(CountryUpdate), returnType: typeof(CountryUnique), keyPropertyMemberName: nameof(Country.Id)) ] public DbSet Countries { get; set; } /// /// Currencies Database Table /// // Generate Add extension methods [EfAddMethods(typeof(CurrencyCreate), typeof(CurrencyUnique))] [EfUpdateMethods( updateType: typeof(CurrencyUpdate), returnType: typeof(CurrencyUnique), keyPropertyMemberName: nameof(Currency.Id)) ] public DbSet Currencies { get; set; } //////////////////////////////////////////////// //////////////////////////////////////////////// /// /// App Configuration /// public IConfiguration Configuration; /// /// CountryDbContext Constructor. /// /// public CountryDbContext(DbContextOptions options) : base(options) { Database.EnsureCreated(); } /// /// On model creating. /// /// protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.ConfigureCurrentDbModel(); } } }