Skip to content

Commit

Permalink
ability to use value + value expressions as values in Linq comparisons.
Browse files Browse the repository at this point in the history
Closes GH-3116
  • Loading branch information
jeremydmiller committed Apr 10, 2024
1 parent 36afb2a commit 1e0c14c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/LinqTests/Bugs/Bug_3116_more_expression_to_constant_issues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Linq;
using System.Threading.Tasks;
using Marten;
using Marten.Testing.Documents;
using Marten.Testing.Harness;

namespace LinqTests.Bugs;

public class Bug_3116_more_expression_to_constant_issues : BugIntegrationContext
{
[Fact]
public async Task query_works()
{
int from = 0;
const int batchSize = 100;

await theStore.BulkInsertDocumentsAsync(Target.GenerateRandomData(100));

await theSession.Query<Target>()
.Where(
e => e.String == "something"
&& e.Number >= from
&& e.Number < from + batchSize)
.OrderBy(r => r.Number)
.ToListAsync();
}
}
9 changes: 9 additions & 0 deletions src/Marten/Linq/Parsing/SimpleExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public ISqlFragment CompareTo(SimpleExpression right, string op)

protected override Expression VisitBinary(BinaryExpression node)
{


switch (node.NodeType)
{
case ExpressionType.Modulo:
Expand All @@ -206,6 +208,13 @@ protected override Expression VisitBinary(BinaryExpression node)

return null;

// GH-3116
case ExpressionType.Add:
Constant = node.ReduceToConstant();
HasConstant = true;

return null;

default:
throw new BadLinqExpressionException(
$"Unsupported nested operator '{node.NodeType}' as an operand in a binary expression");
Expand Down

0 comments on commit 1e0c14c

Please sign in to comment.