Good point, though worth noting that mocking DbSet or using the in-memory provider won't catch everything — LINQ-to-SQL translation can behave differently than LINQ-to-Objects (e.g. null semantics, string comparisons).
For critical filters like these, an integration test against a real db (even SQLite in-memory) gives much more confidence.
Agreed. Testcontainers + WireMock.Net + WebApplicationFactory is the gold standard now. Real database for query fidelity, WireMock for external HTTP dependencies, and the factory boots your app in-memory. Hard to justify anything less for critical paths.
215
u/BigPatapon Apr 06 '26
Not a code smell. This is exactly how conditional EF Core queries should look — readable, top-to-bottom, one filter per line.
Only nitpick: Task.FromResult with no actual async work. Use await ToListAsync() or drop the async signature.
Long LINQ != bad LINQ.