Skip to content

Commit 9742c6b

Browse files
authored
GenerateStringContains(Expression left, Expression right)
1 parent cee7e17 commit 9742c6b

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,12 @@ public Expression GenerateStringConcat(Expression left, Expression right)
132132

133133
public Expression GenerateStringContains(Expression left, Expression right)
134134
{
135-
Expression searchValue = left;
135+
// if (left.Type == typeof(char) && left is ConstantExpression { Value: char character })
136+
// {
137+
// searchValue = Expression.Constant(character.ToString(), typeof(string));
138+
// }
136139

137-
if (left.Type == typeof(char) && left is ConstantExpression { Value: char character })
138-
{
139-
searchValue = Expression.Constant(character.ToString(), typeof(string));
140-
}
141-
142-
return Expression.Call(right, _containsMethod, searchValue);
140+
return Expression.Call(left, _containsMethod, right);
143141
}
144142

145143
public Expression GenerateSubtract(Expression left, Expression right)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ private Expression ParseIn()
414414
{
415415
if (right.Type == typeof(string))
416416
{
417-
accumulate = _expressionHelper.GenerateStringContains(left, right);
417+
accumulate = _expressionHelper.GenerateStringContains(right, left);
418418
}
419419
else
420420
{

test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Entities_Where_In_And()
2727

2828
// Act
2929
var test = _context.Blogs.Include(b => b.Posts)
30-
.Where(@"BlogId in (1000, 1001, 1002) and Name in (""Blog1"", ""Blog2"") && Name.Contains('o') && Name.Contains(""g"")")
30+
.Where(@"BlogId in (1000, 1001, 1002) and Name in (""Blog1"", ""Blog2"") && 'o' in Name && Name.Contains(""g"") && ""l"" in Name")
3131
.ToArray();
3232

3333
// Assert

0 commit comments

Comments
 (0)