using BlueWest.Data; using Microsoft.EntityFrameworkCore; namespace BlueWest.WebApi.MySQL { public static class ModelBuilderExtensions { public static void ProjectDatabaseModel(this ModelBuilder modelBuilder) { // Keys CountryCurrencyModel(modelBuilder); UserModel(modelBuilder); } private static void CountryCurrencyModel(ModelBuilder modelBuilder) { modelBuilder.Entity(builder => { builder.HasKey(x => x.Code); }); modelBuilder.Entity(builder => { builder.HasKey(x => x.Num); }); // Relationships modelBuilder.Entity() .HasMany(ub => ub.Countries) .WithMany(au => au.Currencies); modelBuilder.Entity() .HasMany(ub => ub.Currencies) .WithMany(au => au.Countries); } private static void UserModel(ModelBuilder modelBuilder) { modelBuilder.Entity(builder => builder .HasMany() .WithOne(user => user.Country)); modelBuilder .Entity(builder => builder .HasOne() .WithMany(co => co.Users)); modelBuilder.Entity(builder => { builder.HasOne() .WithMany(x => x.FinanceTransactions) .HasForeignKey(x => x.UserId); }); } } }