88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
using BlueWest.Data;
|
|
using BlueWest.WebApi.EF.Model;
|
|
using MapTo;
|
|
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>
|
|
|
|
[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<Country> Countries { get; set; }
|
|
|
|
/// <summary>
|
|
/// Currencies Database Table
|
|
/// </summary>
|
|
// Generate Add extension methods
|
|
[EfAddMethods(typeof(CurrencyCreate), typeof(CurrencyUnique))]
|
|
|
|
[EfUpdateMethods(
|
|
updateType: typeof(CurrencyUpdate),
|
|
returnType: typeof(CurrencyUnique),
|
|
keyPropertyMemberName: nameof(Currency.Id))
|
|
]
|
|
public DbSet<Currency> Currencies { get; set; }
|
|
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
|
|
/// <summary>
|
|
/// App Configuration
|
|
/// </summary>
|
|
public IConfiguration Configuration;
|
|
|
|
|
|
/// <summary>
|
|
/// CountryDbContext Constructor.
|
|
/// </summary>
|
|
/// <param name="options"></param>
|
|
public CountryDbContext(DbContextOptions<CountryDbContext> options) : base(options)
|
|
{
|
|
Database.EnsureCreated();
|
|
}
|
|
|
|
/// <summary>
|
|
/// On model creating.
|
|
/// </summary>
|
|
/// <param name="modelBuilder"></param>
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
modelBuilder.ConfigureCurrentDbModel();
|
|
}
|
|
|
|
}
|
|
}
|