Best practices
These recommendations apply to CaeriusNet 12 on C# 14, .NET 10 and SQL Server 2022/2025.
- Use
SET NOCOUNT ONin procedures, especially when they return multiple sets. - Treat SQL parameter metadata as a contract: supply
SqlDbType, and add size, precision and scale when needed. Do not useAddWithValue. - Choose cardinality explicitly:
QuerySingle...for unique rows;QueryFirst...only when later rows are intentionally irrelevant. - Use a materialized collection by default. Reach for
StreamAsynconly when its reader lifetime is intentional and one set is returned. - Put the common data-access contract in generated DTO/TVP types; keep manual mappers small and ordinal based.
- Model a TVP as a SQL user-defined type and verify column order/type. Use a replayable
IReadOnlyCollection<T>or explicit streaming factory; manual TVPs need everySqlServerTvpColumnAttributefacet. Test empty, one-row and large inputs. - Cache only deterministic, authorization-safe reads. Redis requires a typed codec; never build cache keys at call sites. Use
DependsOn/Invalidateslogical tags, not literal invalidation keys. - Use Frozen cache for complete snapshots, not lazy refills. Give memory cache a bounded size and expiration.
- Put invalidations on successful writes. Let transactions defer them until commit; if
CaeriusCacheInvalidationException.SqlWasCommittedis true, reconcile rather than retrying blindly. - Keep a transaction short and single-threaded. Do not run concurrent commands through it.
- Keep tracing free of parameter values and secrets; development capture needs an allowlist plus redaction.
- Install AutoContracts separately and run
Verifyin CI after reviewing a freshly pulled v3 manifest. Opt into native SQL Server 2025 JSON/vector only with a major-17 v3 manifest.
The most useful acceptance tests cover cardinality, DBNull, outputs, empty TVPs, result sets 2–10, cache corruption, transaction rollback and SQL Server 2022/2025.
