diff --git a/src/Marten/Linq/Parsing/JsonPathCreator.cs b/src/Marten/Linq/Parsing/JsonPathCreator.cs index 1afb35fec5..53f056f771 100644 --- a/src/Marten/Linq/Parsing/JsonPathCreator.cs +++ b/src/Marten/Linq/Parsing/JsonPathCreator.cs @@ -42,6 +42,7 @@ public string Build(Expression expression) return jsonPath; } + protected override Expression VisitUnary(UnaryExpression node) { if (node.NodeType == ExpressionType.Not) @@ -55,6 +56,16 @@ protected override Expression VisitUnary(UnaryExpression node) return node; } + protected override Expression VisitLambda(Expression node) + { + return Visit(node.Body); + } + protected override Expression VisitParameter(ParameterExpression node) + { + _jsonPathBuilder.Append("@"); + return node; + } + protected override Expression VisitBinary(BinaryExpression node) { if (node.Left is MemberExpression leftMember) diff --git a/src/PatchingTests/Patching/patching_api.cs b/src/PatchingTests/Patching/patching_api.cs index 258bdff513..cc0a195b47 100644 --- a/src/PatchingTests/Patching/patching_api.cs +++ b/src/PatchingTests/Patching/patching_api.cs @@ -829,6 +829,25 @@ public async Task remove_complex_elements_by_predicate() } #endregion + + [Fact] + public async Task remove_simple_element_by_predicate(){ + var target = Target.Random(); + var initialCount = target.NumberArray.Length; + var random = new Random(); + var toRemove = target.NumberArray[random.Next(0, initialCount)]; + + theSession.Store(target); + await theSession.SaveChangesAsync(); + + theSession.Patch(target.Id).Remove(x => x.NumberArray, x => x == toRemove); + await theSession.SaveChangesAsync(); + + await using var query = theStore.QuerySession(); + var target2 = query.Load(target.Id); + target2.NumberArray.ShouldNotContain(t => t == toRemove); + + } [Fact] public async Task throw_exception_if_a_method_call_is_used_for_remove_complex_element_by_predicate()