Skip to content

Commit 1342d13

Browse files
committed
修复group by时候的value null的bug 发布x.6.0.36
1 parent f58fb88 commit 1342d13

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

nuget-publish.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
:start
22
::定义版本
3-
set EFCORE2=2.6.0.35
4-
set EFCORE3=3.6.0.35
5-
set EFCORE5=5.6.0.35
6-
set EFCORE6=6.6.0.35
3+
set EFCORE2=2.6.0.36
4+
set EFCORE3=3.6.0.36
5+
set EFCORE5=5.6.0.36
6+
set EFCORE6=6.6.0.36
77

88
::删除所有bin与obj下的文件
99
@echo off

src/ShardingCore/Extensions/ExpressionExtension.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void SetPropertyValue<T>(this T t, string name, object value)
4646
.SetValue(t,value);
4747
}
4848
}
49-
public static object GetValueByExpression(this object obj, string propertyExpression)
49+
public static (Type propertyType,object value) GetValueByExpression(this object obj, string propertyExpression)
5050
{
5151
var entityType = obj.GetType();
5252
PropertyInfo property;
@@ -78,8 +78,8 @@ public static object GetValueByExpression(this object obj, string propertyExpres
7878
{
7979
throw new ShardingCoreException($"property:[{propertyExpression}] not in type:[{entityType}]");
8080
}
81-
82-
return property.GetValue(obj);
81+
82+
return (property.PropertyType,property.GetValue(obj));
8383
//var lambda = Expression.Lambda(propertyAccess, parameter);
8484
//Delegate fn = lambda.Compile();
8585
//return fn.DynamicInvoke(obj);

src/ShardingCore/Extensions/TypeExtension.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public static bool IsNullableType(this Type type)
1919
{
2020
return !type.IsValueType || (Nullable.GetUnderlyingType(type) != null);
2121
}
22+
23+
public static bool IsComparableType(this Type type)
24+
{
25+
return typeof(IComparable).IsAssignableFrom(type);
26+
}
2227
/// <summary>
2328
/// 检测是否是数字类型,包括nullable的数字类型
2429
/// </summary>

src/ShardingCore/Sharding/Enumerators/StreamMergeAsync/MultiAggregateOrderStreamMergeAsyncEnumerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private List<object> GetCurrentGroupValues(IOrderStreamMergeAsyncEnumerator<T> e
5656
{
5757
var first = enumerator.ReallyCurrent;
5858
return _mergeContext.SelectContext.SelectProperties.Where(o => !(o is SelectAggregateProperty))
59-
.Select(o => first.GetValueByExpression(o.PropertyName)).ToList();
59+
.Select(o => first.GetValueByExpression(o.PropertyName).value).ToList();
6060
}
6161
#if !EFCORE2
6262
public async ValueTask<bool> MoveNextAsync()
@@ -85,7 +85,7 @@ private bool EqualWithGroupValues()
8585
var current = GetCurrentGroupValues(_queue.Peek());
8686
for (int i = 0; i < CurrentGroupValues.Count; i++)
8787
{
88-
if (!CurrentGroupValues[i].Equals(current[i]))
88+
if (!object.Equals(CurrentGroupValues[i],current[i]))
8989
return false;
9090
}
9191

src/ShardingCore/Sharding/Enumerators/StreamMergeAsync/OrderStreamMergeAsyncEnumerator.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ private List<IComparable> GetCurrentOrderValues()
9999
var list = new List<IComparable>(_mergeContext.Orders.Count());
100100
foreach (var order in _mergeContext.Orders)
101101
{
102-
var value = _enumerator.ReallyCurrent.GetValueByExpression(order.PropertyExpression);
102+
var (propertyType,value) = _enumerator.ReallyCurrent.GetValueByExpression(order.PropertyExpression);
103103
if (value is IComparable comparable)
104104
list.Add(comparable);
105+
else if (propertyType.IsComparableType())
106+
{
107+
list.Add((IComparable)value);
108+
}
105109
else
106-
throw new NotSupportedException($"order by value [{order}] must implements IComparable");
110+
{
111+
throw new NotSupportedException($"order by value [{order}] must implements IComparable");
112+
}
107113
}
108114

109115
return list;

0 commit comments

Comments
 (0)