using FinancialApi.Application; using Microsoft.EntityFrameworkCore; namespace FinancialApi.Infrastructure; public class AccountDbContext(DbContextOptions options) : DbContext(options) { public DbSet Accounts => Set(); public DbSet JournalEntries => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasKey(x => x.Id); modelBuilder.Entity().HasData( new Account(1, 10000000.00m, "Credit"), new Account(2, 50000000.00m, "Liability"), new Account(99999, 0.00m, "Revenue") ); modelBuilder.Entity(builder => { builder.HasKey(x => x.Id); builder.OwnsMany(x => x.Lines, line => { line.WithOwner().HasForeignKey("JournalEntryId"); line.Property("Id").ValueGeneratedOnAdd(); line.HasKey("Id"); line.Property(x => x.Type).HasConversion(); }); }); } }