Skip to content

Commit 7d59802

Browse files
authored
Parse in operator before and/or (#524)
1 parent 822d797 commit 7d59802

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Expression ParseAndOperator()
283283
{
284284
Token op = _textParser.CurrentToken;
285285
_textParser.NextToken();
286-
Expression right = ParseComparisonOperator();
286+
Expression right = ParseIn();
287287
CheckAndPromoteOperands(typeof(ILogicalSignatures), op.Id, op.Text, ref left, ref right, op.Pos);
288288
left = Expression.AndAlso(left, right);
289289
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#if EFCORE
2+
using Microsoft.EntityFrameworkCore;
3+
#else
4+
5+
using System.Data.Entity;
6+
7+
#endif
8+
9+
using Xunit;
10+
11+
namespace System.Linq.Dynamic.Core.Tests
12+
{
13+
public partial class EntitiesTests : IDisposable
14+
{
15+
/// <summary>
16+
/// Test for https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/524
17+
/// </summary>
18+
[Fact]
19+
public void Entities_Where_In_And()
20+
{
21+
// Arrange
22+
PopulateTestData();
23+
24+
var expected = _context.Blogs.Include(b => b.Posts).Where(b => new[] { 1, 3, 5 }.Contains(b.BlogId) && new [] { "Blog3", "Blog4" }.Contains(b.Name)).ToArray();
25+
26+
// Act
27+
var test = _context.Blogs.Include(b => b.Posts).Where(@"BlogId in (1, 3, 5) and Name in (""Blog3"", ""Blog4"")").ToArray();
28+
29+
// Assert
30+
Assert.NotEmpty(test);
31+
Assert.Equal(expected, test);
32+
}
33+
}
34+
}

test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.cs

+14
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ public void Parse_ParseAndOperator(string expression, string result)
9393
Check.That(parsedExpression).Equals(result);
9494
}
9595

96+
[Fact]
97+
public void Parse_ParseMultipleInOperators()
98+
{
99+
// Arrange
100+
ParameterExpression[] parameters = { ParameterExpressionHelper.CreateParameterExpression(typeof(Company), "x") };
101+
var sut = new ExpressionParser(parameters, "MainCompanyId in (1, 2) and Name in (\"A\", \"B\")", null, null);
102+
103+
// Act
104+
var parsedExpression = sut.Parse(null).ToString();
105+
106+
// Assert
107+
Check.That(parsedExpression).Equals("(((x.MainCompanyId == 1) OrElse (x.MainCompanyId == 2)) AndAlso ((x.Name == \"A\") OrElse (x.Name == \"B\")))");
108+
}
109+
96110
[Theory]
97111
[InlineData("string(\"\")", "")]
98112
[InlineData("string(\"a\")", "a")]

0 commit comments

Comments
 (0)