Skip to content

Commit 63f1c66

Browse files
SiberaIndustriesxuzhg
authored andcommitted
Fix client-side evaluation for string comparison queries, PR #2053.
1 parent 4aa8831 commit 63f1c66

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Microsoft.AspNet.OData.Shared/Query/Expressions/ExpressionBinderBase.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ namespace Microsoft.AspNet.OData.Query.Expressions
3232
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Relies on many ODataLib classes.")]
3333
public abstract class ExpressionBinderBase
3434
{
35-
internal static readonly MethodInfo StringCompareMethodInfo = typeof(string).GetMethod("Compare", new[] { typeof(string), typeof(string), typeof(StringComparison) });
35+
internal static readonly MethodInfo StringCompareMethodInfo = typeof(string).GetMethod("Compare", new[] { typeof(string), typeof(string) });
3636
internal static readonly MethodInfo GuidCompareMethodInfo = typeof(ExpressionBinderBase).GetMethod("GuidCompare", new[] { typeof(Guid), typeof(Guid) });
3737
internal static readonly string DictionaryStringObjectIndexerName = typeof(Dictionary<string, object>).GetDefaultMembers()[0].Name;
3838

3939
internal static readonly Expression NullConstant = Expression.Constant(null);
4040
internal static readonly Expression FalseConstant = Expression.Constant(false);
4141
internal static readonly Expression TrueConstant = Expression.Constant(true);
4242
internal static readonly Expression ZeroConstant = Expression.Constant(0);
43-
internal static readonly Expression OrdinalStringComparisonConstant = Expression.Constant(StringComparison.Ordinal);
4443

4544
internal static readonly MethodInfo EnumTryParseMethod = typeof(Enum).GetMethods()
4645
.Single(m => m.Name == "TryParse" && m.GetParameters().Length == 2);
@@ -165,7 +164,7 @@ internal Expression CreateBinaryExpression(BinaryOperatorKind binaryOperator, Ex
165164
right = ToNullable(right);
166165
}
167166

168-
if ((left.Type == typeof(Guid) || right.Type == typeof(Guid)))
167+
if (left.Type == typeof(Guid) || right.Type == typeof(Guid))
169168
{
170169
left = ConvertNull(left, typeof(Guid));
171170
right = ConvertNull(right, typeof(Guid));
@@ -197,7 +196,7 @@ internal Expression CreateBinaryExpression(BinaryOperatorKind binaryOperator, Ex
197196
case BinaryOperatorKind.GreaterThanOrEqual:
198197
case BinaryOperatorKind.LessThan:
199198
case BinaryOperatorKind.LessThanOrEqual:
200-
left = Expression.Call(StringCompareMethodInfo, left, right, OrdinalStringComparisonConstant);
199+
left = Expression.Call(StringCompareMethodInfo, left, right);
201200
right = ZeroConstant;
202201
break;
203202
default:

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/QueryComposition/FilterTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public static TheoryDataSet<string, IEnumerable<Product>> OperatorData
5050
data.Add("1 eq 1", products);
5151
data.Add(string.Format("Name eq '{0}'", Encoding(name)), products.Where(p => p.Name == name));
5252
data.Add(string.Format("Name ne '{0}'", Encoding(name)), products.Where(p => p.Name != name));
53-
data.Add(string.Format("Name gt '{0}'", Encoding(name)), products.Where(p => string.Compare(p.Name, name, StringComparison.Ordinal) > 0));
54-
data.Add(string.Format("Name lt '{0}'", Encoding(name)), products.Where(p => string.Compare(p.Name, name, StringComparison.Ordinal) < 0));
53+
data.Add(string.Format("Name gt '{0}'", Encoding(name)), products.Where(p => string.Compare(p.Name, name) > 0));
54+
data.Add(string.Format("Name lt '{0}'", Encoding(name)), products.Where(p => string.Compare(p.Name, name) < 0));
5555
data.Add("ID gt 1", products.Where(p => p.ID > 1));
5656
data.Add("ID ge 1", products.Where(p => p.ID >= 1));
5757
data.Add("ID lt 20", products.Where(p => p.ID < 20));
@@ -320,6 +320,11 @@ public async Task TestFiltersWithXmlSerializer()
320320
var response = await this.Client.SendAsync(request);
321321
var result = await response.Content.ReadAsObject<IEnumerable<Product>>();
322322

323+
if (expected.Count() == 5 && result.Count() ==8)
324+
{
325+
Assert.True(true);
326+
}
327+
323328
Assert.Equal(expected.Count(), result.Count());
324329
for (int i = 0; i < expected.Count(); i++)
325330
{

0 commit comments

Comments
 (0)