Skip to content

fix(generator): discover a DocumentDbContext whatever its class name (#300) - #317

Merged
mrdevrobot merged 1 commit into
EntglDb:mainfrom
CaffeinatedCoder:fix/300-generator-context-suffix
Oct 18, 2026
Merged

mrdevrobot merged 1 commit into
EntglDb:mainfrom
CaffeinatedCoder:fix/300-generator-context-suffix

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Collaborator

What was wrong

The source generator's syntax predicate only passed classes whose name ends in Context (MapperGenerator.IsPotentialDbContext, MapperGenerator.cs:492-499, since v1.0.0). A DocumentDbContext called Shop, AppDb or Store got no generated code and no diagnostic. Its collection properties stayed null, and the first call threw NullReferenceException far from the cause (#300). The README used such a name itself until #298.

Fix

The predicate passes every class with a base list. The semantic check in GetDbContextInfo (InheritsFrom(DocumentDbContext)) already decides what is a context, and it is what makes the pre-filter safe to widen: a class that does not derive from DocumentDbContext still produces nothing. The unused BLiteConventions.DbContextClassSuffix is removed.

Cost: the transform now runs GetDeclaredSymbol for every class with a base list instead of those named *Context. It is an incremental generator, so the result is cached per node and recomputed only for edited nodes. A name filter cannot be kept as a fast path without reporting the skipped classes, and reporting them needs the same semantic check, so a diagnostic would save nothing.

Tests

tests/BLite.Shared/UnsuffixedNameFixtures.cs declares Shop : DocumentDbContext and OnlineShop : Shop, neither named with the suffix. UnsuffixedNameGeneratorTests, three tests: Shop.Customers is generated and round-trips a document; OnlineShop has both its own and the inherited collection; the mapper namespace BLite.Shared.Shop_UnsuffixedNameFixtures_Mappers exists.

On upstream/main (checked by reverting src/BLite.SourceGenerators) all three fail: the fixture compiles, because InitializeCollections is a virtual on the base class, but the collections are null and no mapper namespace exists. With the fix they pass, together with the 47 other generator tests (GlobalNamespace*, DbContextInheritance*, SourceGenerator*).

Full suite dotnet test tests/BLite.Tests (macOS, net10.0): 3094 passed, 4 skipped, 1 failed (IndexPageReleaseTests.DynamicCollection_DropIndex_WhileInserting_KeepsCollectionAndOtherIndexConsistent, TimeoutException: Timed out acquiring collection lock (Insert), while a second suite ran on the same machine; the #303 class of failure, see #302). All 16 tests of that class pass when rerun on their own. This PR changes no runtime code.

Compatibility

Contexts that were generated before are generated the same way. A class that derives from DocumentDbContext and was silently skipped before now gets generated code; if such a class is not partial, the build now reports that (as it does today for a *Context class that is not partial), which is the intended outcome.

Fixes #300

🤖 Generated with Claude Code

…ntglDb#300)

The generator's syntax predicate only passed classes whose name ends in
"Context". A DocumentDbContext called Shop, AppDb or Store got no generated
code and no diagnostic, so its collection properties stayed null and the
first call threw NullReferenceException far from the cause.

The predicate now passes every class with a base list; the semantic check in
GetDbContextInfo (InheritsFrom DocumentDbContext) already decides, and it is
what makes the pre-filter safe to widen. The unused DbContextClassSuffix
convention is removed.

Tests: UnsuffixedNameFixtures (BLite.Shared) declare a context named Shop and
a derived OnlineShop; UnsuffixedNameGeneratorTests check their collections
are generated and round-trip. All three fail on upstream/main (collections
null, no mapper namespace) and pass with the fix.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mrdevrobot

Copy link
Copy Markdown
Contributor

Verified: the three tests fail on 0450b97 (null collections, no mappers) and pass here. Only the "Context" suffix pre-filter is removed; the semantic base-type check still decides.

@mrdevrobot
mrdevrobot merged commit 7184152 into EntglDb:main Oct 18, 2026
2 of 3 checks passed

This branch was successfully deployed

1 active deployment
Production — d1e66585 Deployed Oct 18, 2026 by CaffeinatedCoder via build_and_publish #769
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working package/generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A DocumentDbContext whose class name does not end in "Context" gets no generated code and no diagnostic; its collections stay null

2 participants