This commit is contained in:
xuejiaming 2021-08-27 21:17:40 +08:00
parent c59194eb84
commit b9e9713410
3 changed files with 21 additions and 24 deletions

View File

@ -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
}
}
}

View File

@ -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<TEntity>(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());
}
}

View File

@ -44,17 +44,6 @@ namespace ShardingCore.Sharding.StreamMergeEngines
await enumator.MoveNextAsync();
return enumator;
}
#endif
#if EFCORE2
private async Task<IAsyncEnumerator<T>> GetAsyncEnumerator(IQueryable<T> newQueryable)
{
var enumator = newQueryable.AsAsyncEnumerable().GetEnumerator();
await enumator.MoveNext();
return enumator;
}
#endif
#if !EFCORE2
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = new CancellationToken())
{
return GetShardingEnumerator();
@ -62,6 +51,12 @@ namespace ShardingCore.Sharding.StreamMergeEngines
#endif
#if EFCORE2
private async Task<IAsyncEnumerator<T>> GetAsyncEnumerator(IQueryable<T> newQueryable)
{
var enumator = newQueryable.AsAsyncEnumerable().GetEnumerator();
await enumator.MoveNext();
return enumator;
}
IAsyncEnumerator<T> IAsyncEnumerable<T>.GetEnumerator()
{
return GetShardingEnumerator();