diff --git a/src/Http/Wolverine.Http.Tests/Marten/reacting_to_read_aggregate.cs b/src/Http/Wolverine.Http.Tests/Marten/reacting_to_read_aggregate.cs index 150955a39..838b74dc0 100644 --- a/src/Http/Wolverine.Http.Tests/Marten/reacting_to_read_aggregate.cs +++ b/src/Http/Wolverine.Http.Tests/Marten/reacting_to_read_aggregate.cs @@ -124,6 +124,8 @@ await theHost.Scenario(x => public static class LetterAggregateEndpointWithValidation { + public static void Before(Guid id) { } + public static ProblemDetails Validate(LetterAggregate letters) { if (letters.ACount is 0) @@ -142,6 +144,8 @@ public static LetterAggregate PostLetter([WriteAggregate(Required = true, OnMiss public static class LetterAggregateEndpoint { + public static void Load(Guid id) { } + #region sample_read_aggregate_fine_grained_validation_control // Straight up 404 on missing diff --git a/src/Persistence/Wolverine.Marten/Codegen/MartenQueryingFrame.cs b/src/Persistence/Wolverine.Marten/Codegen/MartenQueryingFrame.cs index 44ba754ef..74c065535 100644 --- a/src/Persistence/Wolverine.Marten/Codegen/MartenQueryingFrame.cs +++ b/src/Persistence/Wolverine.Marten/Codegen/MartenQueryingFrame.cs @@ -107,5 +107,17 @@ public override IEnumerable FindVariables(IMethodVariables chain) _cancellation = chain.FindVariable(typeof(CancellationToken)); yield return _cancellation; + + // This ensures those variables are declared before we try to use them in the batch enlistment code + foreach (var op in _operations) + { + if (op is Frame frame) + { + foreach (var variable in frame.FindVariables(chain)) + { + yield return variable; + } + } + } } } \ No newline at end of file