修复group by时候的value null的bug 发布x.6.0.36

This commit is contained in:
xuejiaming 2022-09-22 14:52:34 +08:00
parent f58fb88c10
commit 1342d13eb3
5 changed files with 22 additions and 11 deletions

View File

@ -1,9 +1,9 @@
:start :start
::定义版本 ::定义版本
set EFCORE2=2.6.0.35 set EFCORE2=2.6.0.36
set EFCORE3=3.6.0.35 set EFCORE3=3.6.0.36
set EFCORE5=5.6.0.35 set EFCORE5=5.6.0.36
set EFCORE6=6.6.0.35 set EFCORE6=6.6.0.36
::删除所有bin与obj下的文件 ::删除所有bin与obj下的文件
@echo off @echo off

View File

@ -46,7 +46,7 @@ namespace ShardingCore.Extensions
.SetValue(t,value); .SetValue(t,value);
} }
} }
public static object GetValueByExpression(this object obj, string propertyExpression) public static (Type propertyType,object value) GetValueByExpression(this object obj, string propertyExpression)
{ {
var entityType = obj.GetType(); var entityType = obj.GetType();
PropertyInfo property; PropertyInfo property;
@ -78,8 +78,8 @@ namespace ShardingCore.Extensions
{ {
throw new ShardingCoreException($"property:[{propertyExpression}] not in type:[{entityType}]"); throw new ShardingCoreException($"property:[{propertyExpression}] not in type:[{entityType}]");
} }
return property.GetValue(obj); return (property.PropertyType,property.GetValue(obj));
//var lambda = Expression.Lambda(propertyAccess, parameter); //var lambda = Expression.Lambda(propertyAccess, parameter);
//Delegate fn = lambda.Compile(); //Delegate fn = lambda.Compile();
//return fn.DynamicInvoke(obj); //return fn.DynamicInvoke(obj);

View File

@ -19,6 +19,11 @@ namespace ShardingCore.Extensions
{ {
return !type.IsValueType || (Nullable.GetUnderlyingType(type) != null); return !type.IsValueType || (Nullable.GetUnderlyingType(type) != null);
} }
public static bool IsComparableType(this Type type)
{
return typeof(IComparable).IsAssignableFrom(type);
}
/// <summary> /// <summary>
/// 检测是否是数字类型,包括nullable的数字类型 /// 检测是否是数字类型,包括nullable的数字类型
/// </summary> /// </summary>

View File

@ -56,7 +56,7 @@ namespace ShardingCore.Sharding.Enumerators
{ {
var first = enumerator.ReallyCurrent; var first = enumerator.ReallyCurrent;
return _mergeContext.SelectContext.SelectProperties.Where(o => !(o is SelectAggregateProperty)) return _mergeContext.SelectContext.SelectProperties.Where(o => !(o is SelectAggregateProperty))
.Select(o => first.GetValueByExpression(o.PropertyName)).ToList(); .Select(o => first.GetValueByExpression(o.PropertyName).value).ToList();
} }
#if !EFCORE2 #if !EFCORE2
public async ValueTask<bool> MoveNextAsync() public async ValueTask<bool> MoveNextAsync()
@ -85,7 +85,7 @@ namespace ShardingCore.Sharding.Enumerators
var current = GetCurrentGroupValues(_queue.Peek()); var current = GetCurrentGroupValues(_queue.Peek());
for (int i = 0; i < CurrentGroupValues.Count; i++) for (int i = 0; i < CurrentGroupValues.Count; i++)
{ {
if (!CurrentGroupValues[i].Equals(current[i])) if (!object.Equals(CurrentGroupValues[i],current[i]))
return false; return false;
} }

View File

@ -99,11 +99,17 @@ namespace ShardingCore.Sharding.Enumerators
var list = new List<IComparable>(_mergeContext.Orders.Count()); var list = new List<IComparable>(_mergeContext.Orders.Count());
foreach (var order in _mergeContext.Orders) foreach (var order in _mergeContext.Orders)
{ {
var value = _enumerator.ReallyCurrent.GetValueByExpression(order.PropertyExpression); var (propertyType,value) = _enumerator.ReallyCurrent.GetValueByExpression(order.PropertyExpression);
if (value is IComparable comparable) if (value is IComparable comparable)
list.Add(comparable); list.Add(comparable);
else if (propertyType.IsComparableType())
{
list.Add((IComparable)value);
}
else else
throw new NotSupportedException($"order by value [{order}] must implements IComparable"); {
throw new NotSupportedException($"order by value [{order}] must implements IComparable");
}
} }
return list; return list;