# REPOSITORY LAYER KNOWLEDGE BASE **Generated:** 2026-01-28 **Parent:** EmailBill/AGENTS.md ## OVERVIEW Data access layer using FreeSql with BaseRepository pattern and global usings. ## STRUCTURE ``` Repository/ ├── BaseRepository.cs # Generic repository base ├── GlobalUsings.cs # Common imports ├── BudgetRepository.cs # Budget data access ├── TransactionRecordRepository.cs # Transaction data access ├── EmailMessageRepository.cs # Email data access └── TransactionStatisticsDto.cs # Statistics DTOs ``` ## WHERE TO LOOK | Task | Location | Notes | |------|----------|-------| | Base patterns | BaseRepository.cs | Generic CRUD operations | | Budget data | BudgetRepository.cs | Budget queries and updates | | Transaction data | TransactionRecordRepository.cs | Financial data access | | Email data | EmailMessageRepository.cs | Email processing storage | | Statistics | TransactionStatisticsDto.cs | Data transfer objects | ## CONVENTIONS - Inherit from BaseRepository for all repositories - Use GlobalUsings.cs for shared imports - Async/await pattern for all database operations - Method names: GetAllAsync, GetByIdAsync, InsertAsync, UpdateAsync - Return domain entities, not DTOs (except in query results) ## ANTI-PATTERNS (THIS LAYER) - Never return anonymous types from methods - Don't expose FreeSql ISelect directly - Avoid business logic in repositories - No synchronous database calls - Don't mix data access with service logic ## UNIQUE STYLES - Generic constraints: where T : BaseEntity - Fluent query building with FreeSql extension methods - Paged query patterns for large datasets