[#172] bug修复

This commit is contained in:
xuejiaming 2022-07-18 23:30:05 +08:00
parent 703bf84396
commit 3f44744325
3 changed files with 26 additions and 5 deletions

View File

@ -162,7 +162,8 @@ namespace ShardingCore.Core.Internal.Visitors
member.Expression is MemberExpression))
|| expression is MethodCallExpression
|| (expression is UnaryExpression unaryExpression &&
unaryExpression.NodeType is ExpressionType.Convert);
unaryExpression.NodeType is ExpressionType.Convert)
|| expression.NodeType == ExpressionType.ArrayIndex;
}
private bool IsMethodCall(Expression expression)
@ -460,13 +461,15 @@ namespace ShardingCore.Core.Internal.Visitors
return RoutePredicateExpression.Default;
}
private RoutePredicateExpression ParseNamedComparison(BinaryExpression binaryExpression,MethodCallExpression methodCallExpression)
private RoutePredicateExpression ParseNamedComparison(BinaryExpression binaryExpression,
MethodCallExpression methodCallExpression)
{
if (methodCallExpression.GetComparisonLeftAndRight(out var result))
{
return ParseCompare(methodCallExpression, result.Left, result.Right,
binaryExpression.NodeType, (int)GetExpressionValue(binaryExpression.Right));
}
return RoutePredicateExpression.Default;
}
@ -557,7 +560,8 @@ namespace ShardingCore.Core.Internal.Visitors
{
return ParseConditionOnRight0(false, predicateRightResult, binaryExpression.Left,
binaryExpression.NodeType);
} else if (binaryExpression.IsNamedComparison(out var methodCallExpression))
}
else if (binaryExpression.IsNamedComparison(out var methodCallExpression))
{
return ParseNamedComparison(binaryExpression, methodCallExpression);
}
@ -589,7 +593,7 @@ namespace ShardingCore.Core.Internal.Visitors
}
if (binaryExpression.Left is UnaryExpression unaryExpression1 &&
(binaryExpression.Right is MemberExpression ))
(binaryExpression.Right is MemberExpression))
left = Resolve(unaryExpression1);
if (binaryExpression.Right is UnaryExpression unaryExpression2 &&
(binaryExpression.Left is MemberExpression))

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@ -114,8 +115,22 @@ namespace ShardingCore.Core.Internal.Visitors
}
default:
{
if (expression is BinaryExpression binaryExpression&&expression.NodeType == ExpressionType.ArrayIndex)
{
var index = GetExpressionValue(binaryExpression.Right);
if (index is int i)
{
var arrayObject = GetExpressionValue(binaryExpression.Left);
if (arrayObject is IList list)
{
return list[i];
}
}
}
//TODO: better messaging
throw new ShardingCoreException("cant get value " + expression);
}
}
}
}

View File

@ -91,11 +91,13 @@ namespace ShardingCore.CommonTest
var id = "1";
var times = new []{queryTime};
var times1 = new List<DateTime>(){queryTime};
var times2 = new []{queryTime,queryTime2};
var obj1 = new {time=new DateTime(2022, 1, 2)};
var queryables=new List<IQueryable<TestTimeEntity>>()
{
// new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time==times[0]),
new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time==times2[0]),
new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time>=times2[0]&&o.Time<times2[1]),
new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time>=queryTime&&o.Time<queryTime2),
new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time==queryTime),
new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time>=queryTime&&o.Time<queryTime2),