Skip to content

Fix FetchForWriting with natural keys without explicit projection registration#4213

Merged
jeremydmiller merged 2 commits intomasterfrom
fix/4199-natural-key-fetch-for-writing
Mar 28, 2026
Merged

Fix FetchForWriting with natural keys without explicit projection registration#4213
jeremydmiller merged 2 commits intomasterfrom
fix/4199-natural-key-fetch-for-writing

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

  • Fix Npgsql.PostgresException: '42P01: relation "public.mt_natural_key_..." does not exist' when using FetchForWriting<TDoc, TNaturalKey>() without explicitly registering Projections.Snapshot<TDoc>(Inline)
  • Reset schema existence checks after auto-registering a natural key projection so the natural key table gets created
  • Scan for [NaturalKeyAggregate] attributes emitted by JasperFx.Events.SourceGenerator 1.4.0 to pre-register projections at startup
  • Update JasperFx packages: JasperFx 1.21.5, JasperFx.Events 1.24.2, JasperFx.Events.SourceGenerator 1.4.0

Closes #4199

Depends on JasperFx/jasperfx#172

Test plan

🤖 Generated with Claude Code

jeremydmiller and others added 2 commits March 27, 2026 12:53
…istration

When using FetchForWriting<TDoc, TId> with a natural key type and no explicit
Projections.Snapshot<TDoc>(Inline) call, Marten now:

1. Auto-registers the snapshot projection on first FetchForWriting call
2. Resets schema existence checks so the natural key table gets created
3. At startup, scans for [NaturalKeyAggregate] attributes emitted by the
   JasperFx.Events source generator to pre-register projections

This fixes the Npgsql.PostgresException: '42P01: relation
"public.mt_natural_key_..." does not exist' error reported in #4199.

Closes #4199

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- JasperFx 1.21.4 → 1.21.5
- JasperFx.Events 1.24.1 → 1.24.2 (NaturalKeyAggregateAttribute)
- JasperFx.Events.SourceGenerator 1.3.0 → 1.4.0 (natural key discovery)
- Microsoft.Extensions.Hosting.Abstractions 8.0.0 → 8.0.1 (transitive dep)
- Microsoft.Extensions.Diagnostics.HealthChecks 8.0.0 → 8.0.1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit ade46c0 into master Mar 28, 2026
1 of 6 checks passed
@jeremydmiller jeremydmiller deleted the fix/4199-natural-key-fetch-for-writing branch March 28, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Npgsql.PostgresException when using FetchForWriting() with natural keys

1 participant