diff --git a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs index a5ded32e..0606324b 100644 --- a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs +++ b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs @@ -411,6 +411,16 @@ Expression ParseLogicalAndOrOperator() switch (op.Id) { case TokenId.Amphersand: + int parseValue; + if (left.Type == typeof(string) && left.NodeType == ExpressionType.Constant && int.TryParse((string)((ConstantExpression)left).Value, out parseValue) && TypeHelper.IsNumericType(right.Type)) + { + left = Expression.Constant(parseValue); + } + else if (right.Type == typeof(string) && right.NodeType == ExpressionType.Constant && int.TryParse((string)((ConstantExpression)right).Value, out parseValue) && TypeHelper.IsNumericType(left.Type)) + { + right = Expression.Constant(parseValue); + } + // When at least one side of the operator is a string, consider it's a VB-style concatenation operator. // Doesn't break any other function since logical AND with a string is invalid anyway. if (left.Type == typeof(string) || right.Type == typeof(string)) diff --git a/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs b/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs index f401906b..154c66fe 100644 --- a/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs @@ -1402,6 +1402,23 @@ public void ExpressionTests_StringConcatenation() Assert.Equal("FirstNamex y", resultAddWithAmpAndParams.First()); } + [Fact] + public void ExpressionTests_BinaryAnd() + { + // Arrange + var baseQuery = new[] { new { Int = 5 } }.AsQueryable(); + + // Act + var resultAddWithAmp = baseQuery.Select("it.Int & @0", "4"); + var resultAddWithAmp2 = baseQuery.Select("it.Int & @0", "2"); + var resultAddWithAmp3 = baseQuery.Select("@0 & it.Int", "4"); + + // Assert + Assert.Equal(4, resultAddWithAmp.First()); + Assert.Equal(0, resultAddWithAmp2.First()); + Assert.Equal(4, resultAddWithAmp3.First()); + } + [Fact] public void ExpressionTests_Subtract_Number() {