From b9e9713410c4614f536cd285def9feef1721d7e5 Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Fri, 27 Aug 2021 21:17:40 +0800 Subject: [PATCH] 1 --- .../Extensions/ShardingExtension.cs | 14 +++++++++++++- .../AbstractInMemoryAsyncMergeEngine.cs | 14 ++------------ .../AsyncEnumerableStreamMergeEngine.cs | 17 ++++++----------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/ShardingCore/Extensions/ShardingExtension.cs b/src/ShardingCore/Extensions/ShardingExtension.cs index e73e68c6..f20dbb43 100644 --- a/src/ShardingCore/Extensions/ShardingExtension.cs +++ b/src/ShardingCore/Extensions/ShardingExtension.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq.Expressions; using System.Text; +using Microsoft.EntityFrameworkCore.Infrastructure; using ShardingCore.Exceptions; using ShardingCore.Sharding.Abstractions; @@ -44,7 +46,17 @@ namespace ShardingCore.Extensions public static string FormatRouteTail2ModelCacheKey(this string originalTail) { return $"{ShardingTableDbContextFormat}{originalTail}"; - ; + } + + public static string ShardingPrint(this Expression expression) + { + +#if !EFCORE2 + return expression.Print(); +#endif +#if EFCORE2 + return expression.ToString(); +#endif } } } diff --git a/src/ShardingCore/Sharding/StreamMergeEngines/Abstractions/AbstractInMemoryAsyncMergeEngine.cs b/src/ShardingCore/Sharding/StreamMergeEngines/Abstractions/AbstractInMemoryAsyncMergeEngine.cs index 60208e88..6bd5017a 100644 --- a/src/ShardingCore/Sharding/StreamMergeEngines/Abstractions/AbstractInMemoryAsyncMergeEngine.cs +++ b/src/ShardingCore/Sharding/StreamMergeEngines/Abstractions/AbstractInMemoryAsyncMergeEngine.cs @@ -31,12 +31,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions { _methodCallExpression = methodCallExpression; var expression = methodCallExpression.Arguments.FirstOrDefault(o => typeof(IQueryable).IsAssignableFrom(o.Type)) -#if !EFCORE2 - ?? throw new InvalidOperationException(methodCallExpression.Print()); -#endif -#if EFCORE2 - ?? throw new InvalidOperationException(methodCallExpression.ToString()); -#endif + ?? throw new InvalidOperationException(methodCallExpression.ShardingPrint()); _queryable = new EnumerableQuery(expression); _secondExpression = methodCallExpression.Arguments.FirstOrDefault(o => !typeof(IQueryable).IsAssignableFrom(o.Type)); @@ -48,12 +43,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions { if (methodCallExpression.Arguments.Count == 2) { -#if !EFCORE2 - throw new InvalidOperationException(methodCallExpression.Print()); -#endif -#if EFCORE2 - throw new InvalidOperationException(methodCallExpression.ToString()); -#endif + throw new InvalidOperationException(methodCallExpression.ShardingPrint()); } } diff --git a/src/ShardingCore/Sharding/StreamMergeEngines/AsyncEnumerableStreamMergeEngine.cs b/src/ShardingCore/Sharding/StreamMergeEngines/AsyncEnumerableStreamMergeEngine.cs index 311a45fe..79d04cf8 100644 --- a/src/ShardingCore/Sharding/StreamMergeEngines/AsyncEnumerableStreamMergeEngine.cs +++ b/src/ShardingCore/Sharding/StreamMergeEngines/AsyncEnumerableStreamMergeEngine.cs @@ -44,17 +44,6 @@ namespace ShardingCore.Sharding.StreamMergeEngines await enumator.MoveNextAsync(); return enumator; } -#endif -#if EFCORE2 - private async Task> GetAsyncEnumerator(IQueryable newQueryable) - { - var enumator = newQueryable.AsAsyncEnumerable().GetEnumerator(); - await enumator.MoveNext(); - return enumator; - } -#endif -#if !EFCORE2 - public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = new CancellationToken()) { return GetShardingEnumerator(); @@ -62,6 +51,12 @@ namespace ShardingCore.Sharding.StreamMergeEngines #endif #if EFCORE2 + private async Task> GetAsyncEnumerator(IQueryable newQueryable) + { + var enumator = newQueryable.AsAsyncEnumerable().GetEnumerator(); + await enumator.MoveNext(); + return enumator; + } IAsyncEnumerator IAsyncEnumerable.GetEnumerator() { return GetShardingEnumerator();