# ENTITY LAYER KNOWLEDGE BASE

**Generated:** 2026-01-28
**Parent:** EmailBill/AGENTS.md

## OVERVIEW
Database entities using FreeSql ORM with BaseEntity inheritance pattern.

## STRUCTURE
```
Entity/
├── BaseEntity.cs          # Base entity with Snowflake ID
├── GlobalUsings.cs        # Common imports
├── BudgetRecord.cs        # Budget tracking entity
├── TransactionRecord.cs   # Transaction entity
├── EmailMessage.cs        # Email processing entity
└── MessageRecord.cs       # Message entity
```

## WHERE TO LOOK
| Task | Location | Notes |
|------|----------|-------|
| Base entity pattern | BaseEntity.cs | Snowflake ID, audit fields |
| Budget entities | BudgetRecord.cs, BudgetArchive.cs | Budget tracking |
| Transaction entities | TransactionRecord.cs, TransactionPeriodic.cs | Financial transactions |
| Email entities | EmailMessage.cs, MessageRecord.cs | Email processing |

## CONVENTIONS
- Inherit from BaseEntity for all entities
- Use [Column] attributes for FreeSql mapping
- Snowflake IDs via YitIdHelper.NextId()
- Chinese comments for business logic
- XML docs for public APIs

## ANTI-PATTERNS (THIS LAYER)
- Never use DateTime.Now (use IDateTimeProvider)
- Don't skip BaseEntity inheritance
- Avoid complex business logic in entities
- No database queries in entity classes

## UNIQUE STYLES
- Fluent Chinese naming for business concepts
- Audit fields (CreateTime, UpdateTime) automatic
- Soft delete patterns via UpdateTime nullability