Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Marten/Linq/Parsing/JsonPathCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public string Build(Expression expression)
return jsonPath;
}


protected override Expression VisitUnary(UnaryExpression node)
{
if (node.NodeType == ExpressionType.Not)
Expand All @@ -55,6 +56,16 @@ protected override Expression VisitUnary(UnaryExpression node)
return node;
}

protected override Expression VisitLambda<T>(Expression<T> 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)
Expand Down
19 changes: 19 additions & 0 deletions src/PatchingTests/Patching/patching_api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(target.Id).Remove(x => x.NumberArray, x => x == toRemove);
await theSession.SaveChangesAsync();

await using var query = theStore.QuerySession();
var target2 = query.Load<Target>(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()
Expand Down