--- description: "Implement FinanceDbContext with fluent entity configurations, indexes, relationships, and SQLite connection setup" agent: "agent" --- # Step 3: DbContext & Mappings Create `src/Duempelkas.Infrastructure/Persistence/FinanceDbContext.cs`. ## DbSets - `DbSet Accounts` - `DbSet AccountYears` - `DbSet Entries` - `DbSet TransferLinks` ## Connection - Accept SQLite connection string via constructor options. - Default path: `Data Source=duempelkas.db` in the app's base directory. ## Entity Configurations (use `OnModelCreating` with `IEntityTypeConfiguration` or inline) ### Account - `Name` required, max length 200. - Cascade delete → AccountYears. ### AccountYear - Unique index on `(AccountId, Year)`. - `OpeningBalance` column type `decimal(18,2)`. - Cascade delete → Entries. ### Entry - Index on `(AccountYearId, Date)`. - `Amount` column type `decimal(18,2)`. - `Type` stored as int. - Optional FK to TransferLink (`TransferLinkId`), restrict delete. ### TransferLink - Unique index on `SourceEntryId`. - Unique index on `TargetEntryId`. - Relationships to SourceEntry and TargetEntry with `DeleteBehavior.Restrict`. ## Notes - Use separate `IEntityTypeConfiguration` classes in `Persistence/Configurations/`. - Do not auto-generate migrations; the initial migration will be created manually later.