using FinancialApi.Domain.Entities; 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, AccountType.Borrow), new Account(2, 50000000.00m, AccountType.Spend), new Account(99999, 0.00m, AccountType.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(); } ); } ); } }