优化修复bug
This commit is contained in:
parent
547d8b8cd5
commit
138584bbd8
|
@ -26,6 +26,7 @@ namespace Sample.SqlServer.Controllers
|
|||
[HttpGet]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
var resultx11231 = await _defaultTableDbContext.Set<SysUserMod>().Where(o => o.Age == 198198).Select(o=>o.Id).ContainsAsync("1981");
|
||||
var resultx1121 = await _defaultTableDbContext.Set<SysUserMod>().Where(o => o.Id == "198").SumAsync(o=>o.Age);
|
||||
var resultx111 = await _defaultTableDbContext.Set<SysUserMod>().FirstOrDefaultAsync(o => o.Id == "198");
|
||||
var resultx2 = await _defaultTableDbContext.Set<SysUserMod>().CountAsync(o => o.Age<=10);
|
||||
|
|
|
@ -8,6 +8,7 @@ using ShardingCore.Core.VirtualTables;
|
|||
using ShardingCore.DbContexts;
|
||||
using ShardingCore.DbContexts.Abstractions;
|
||||
using ShardingCore.DbContexts.ShardingDbContexts;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
using ShardingCore.TableCreator;
|
||||
|
|
|
@ -15,6 +15,6 @@ namespace ShardingCore.DbContexts
|
|||
public interface IShardingDbContextFactory
|
||||
{
|
||||
DbContext Create(ShardingDbContextOptions shardingDbContextOptions);
|
||||
DbContext Create(DbConnection dbConnection,string tail);
|
||||
//DbContext Create(DbConnection dbConnection,string tail);
|
||||
}
|
||||
}
|
|
@ -53,11 +53,12 @@ namespace ShardingCore.DbContexts
|
|||
return dbContext;
|
||||
}
|
||||
|
||||
public DbContext Create(DbConnection dbConnection,string tail)
|
||||
{
|
||||
var shardingDbContextOptions =
|
||||
new ShardingDbContextOptions(_dbContextOptionsProvider.GetDbContextOptions(dbConnection), tail);
|
||||
return Create(shardingDbContextOptions);
|
||||
}
|
||||
|
||||
//public DbContext Create(DbConnection dbConnection,string tail)
|
||||
//{
|
||||
// var shardingDbContextOptions =
|
||||
// new ShardingDbContextOptions(_dbContextOptionsProvider.GetDbContextOptions(dbConnection), tail);
|
||||
// return Create(shardingDbContextOptions);
|
||||
//}
|
||||
}
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
|
||||
namespace ShardingCore.Sharding
|
||||
namespace ShardingCore.EFCores
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Saturday, 14 August 2021 10:17:43
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Saturday, 14 August 2021 10:17:43
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class ShardingDbSetSource:IDbSetSource
|
||||
{
|
||||
private static readonly MethodInfo _genericCreateSet
|
|
@ -1,25 +1,14 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Query.Internal;
|
||||
using ShardingCore.Core;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Internal;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShardingCore.Sharding
|
||||
namespace ShardingCore.EFCores
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
|
@ -1,28 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.EntityFrameworkCore.Query.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShardingCore.Core.ShardingAccessors;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
using ShardingCore.Sharding.StreamMergeEngines;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.AggregateMergeEngines;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShardingCore.EFCores
|
||||
{
|
||||
|
@ -122,6 +117,8 @@ namespace ShardingCore.EFCores
|
|||
return EnsureMergeExecuteAsync2<TResult>(typeof(SumAsyncInMemoryMergeEngine<,>), shardingDbContext, methodCallExpression, cancellationToken);
|
||||
case nameof(Enumerable.Average):
|
||||
return EnsureMergeExecuteAsync2<TResult>(typeof(AverageAsyncInMemoryMergeEngine<,>), shardingDbContext, methodCallExpression, cancellationToken);
|
||||
case nameof(Enumerable.Contains):
|
||||
return EnsureMergeExecuteAsync<TResult>(typeof(ContainsAsyncInMemoryMergeEngine<>), shardingDbContext, methodCallExpression, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,19 @@ namespace ShardingCore.Sharding.Abstractions
|
|||
/// 真实的DbContext 类型
|
||||
/// </summary>
|
||||
Type ActualDbContextType { get;}
|
||||
|
||||
/// <summary>
|
||||
/// 创建DbContext
|
||||
/// </summary>
|
||||
/// <param name="track"></param>
|
||||
/// <param name="tail"></param>
|
||||
/// <returns></returns>
|
||||
DbContext GetDbContext(bool track,string tail);
|
||||
/// <summary>
|
||||
/// 根据实体创建db context
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
DbContext CreateGenericDbContext<T>(T entity) where T : class;
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding.Enumerators
|
||||
namespace ShardingCore.Sharding.Abstractions
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
|
@ -1,85 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace ShardingCore.Sharding.Internal
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/15 8:50:09
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
internal static class NonCapturingLazyInitializer
|
||||
{
|
||||
public static TValue EnsureInitialized<TParam, TValue>(
|
||||
ref TValue target,
|
||||
TParam param,
|
||||
[NotNull] Func<TParam, TValue> valueFactory)
|
||||
where TValue : class
|
||||
{
|
||||
var tmp = Volatile.Read(ref target);
|
||||
if (tmp != null)
|
||||
{
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Interlocked.CompareExchange(ref target, valueFactory(param), null);
|
||||
|
||||
return target!;
|
||||
}
|
||||
|
||||
public static TValue EnsureInitialized<TParam1, TParam2, TValue>(
|
||||
ref TValue target,
|
||||
TParam1 param1,
|
||||
TParam2 param2,
|
||||
Func<TParam1, TParam2, TValue> valueFactory)
|
||||
where TValue : class
|
||||
{
|
||||
var tmp = Volatile.Read(ref target);
|
||||
if (tmp != null)
|
||||
{
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Interlocked.CompareExchange(ref target, valueFactory(param1, param2), null);
|
||||
|
||||
return target!;
|
||||
}
|
||||
|
||||
public static TValue EnsureInitialized<TValue>(
|
||||
ref TValue target,
|
||||
TValue value)
|
||||
where TValue : class
|
||||
{
|
||||
var tmp = Volatile.Read(ref target);
|
||||
if (tmp != null)
|
||||
{
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Interlocked.CompareExchange(ref target, value, null);
|
||||
|
||||
return target!;
|
||||
}
|
||||
|
||||
public static TValue EnsureInitialized<TParam, TValue>(
|
||||
ref TValue target,
|
||||
TParam param,
|
||||
Action<TParam> valueFactory)
|
||||
where TValue : class
|
||||
{
|
||||
if (Volatile.Read(ref target) != null)
|
||||
{
|
||||
return target!;
|
||||
}
|
||||
|
||||
valueFactory(param);
|
||||
|
||||
return Volatile.Read(ref target)!;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Diagnostics.CodeAnalysis;
|
||||
//using System.Linq;
|
||||
//using System.Linq.Expressions;
|
||||
//using System.Reflection;
|
||||
//using System.Threading;
|
||||
//using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
//using Microsoft.EntityFrameworkCore.Query;
|
||||
//using Microsoft.EntityFrameworkCore.Query.Internal;
|
||||
//using ShardingCore.Exceptions;
|
||||
//using ShardingCore.Extensions;
|
||||
//using ShardingCore.Sharding.Abstractions;
|
||||
//using ShardingCore.Sharding.Enumerators;
|
||||
|
||||
//namespace ShardingCore.Sharding.Query
|
||||
//{
|
||||
///*
|
||||
//* @Author: xjm
|
||||
//* @Description:
|
||||
//* @Date: Saturday, 14 August 2021 14:25:27
|
||||
//* @Email: 326308290@qq.com
|
||||
//*/
|
||||
// public class ShardingEntityQueryProvider: IAsyncQueryProvider
|
||||
// {
|
||||
// private static readonly MethodInfo _genericCreateQueryMethod
|
||||
// = typeof(ShardingEntityQueryProvider).GetRuntimeMethods()
|
||||
// .Single(m => (m.Name == "CreateQuery") && m.IsGenericMethod);
|
||||
|
||||
// private readonly MethodInfo _genericExecuteMethod;
|
||||
|
||||
// private readonly IQueryCompiler _queryCompiler;
|
||||
// private readonly ICurrentDbContext _currentDbContext;
|
||||
// private readonly IStreamMergeContextFactory _streamMergeContextFactory;
|
||||
|
||||
// /// <summary>
|
||||
// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
|
||||
// /// the same compatibility standards as public APIs. It may be changed or removed without notice in
|
||||
// /// any release. You should only use it directly in your code with extreme caution and knowing that
|
||||
// /// doing so can result in application failures when updating to a new Entity Framework Core release.
|
||||
// /// </summary>
|
||||
// public ShardingEntityQueryProvider(IQueryCompiler queryCompiler,ICurrentDbContext currentDbContext)
|
||||
// {
|
||||
// _queryCompiler = queryCompiler;
|
||||
// _currentDbContext = currentDbContext;
|
||||
// _genericExecuteMethod = queryCompiler.GetType()
|
||||
// .GetRuntimeMethods()
|
||||
// .Single(m => (m.Name == "Execute") && m.IsGenericMethod);
|
||||
// _streamMergeContextFactory = ShardingContainer.GetService<IStreamMergeContextFactory>();
|
||||
// }
|
||||
|
||||
// public ICurrentDbContext GetCurrentDbContext()
|
||||
// {
|
||||
// return _currentDbContext;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
|
||||
// /// the same compatibility standards as public APIs. It may be changed or removed without notice in
|
||||
// /// any release. You should only use it directly in your code with extreme caution and knowing that
|
||||
// /// doing so can result in application failures when updating to a new Entity Framework Core release.
|
||||
// /// </summary>
|
||||
// public virtual IQueryable<TElement> CreateQuery<TElement>(Expression expression)
|
||||
// => new ShardingEntityQueryable<TElement>(this, expression);
|
||||
|
||||
// /// <summary>
|
||||
// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
|
||||
// /// the same compatibility standards as public APIs. It may be changed or removed without notice in
|
||||
// /// any release. You should only use it directly in your code with extreme caution and knowing that
|
||||
// /// doing so can result in application failures when updating to a new Entity Framework Core release.
|
||||
// /// </summary>
|
||||
// public virtual IQueryable CreateQuery(Expression expression)
|
||||
// => (IQueryable)_genericCreateQueryMethod
|
||||
// .MakeGenericMethod(expression.Type.GetSequenceType())
|
||||
// .Invoke(this, new object[] { expression });
|
||||
|
||||
// /// <summary>
|
||||
// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
|
||||
// /// the same compatibility standards as public APIs. It may be changed or removed without notice in
|
||||
// /// any release. You should only use it directly in your code with extreme caution and knowing that
|
||||
// /// doing so can result in application failures when updating to a new Entity Framework Core release.
|
||||
// /// </summary>
|
||||
// public virtual TResult Execute<TResult>(Expression expression)
|
||||
// => throw new NotSupportedException();
|
||||
|
||||
// /// <summary>
|
||||
// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
|
||||
// /// the same compatibility standards as public APIs. It may be changed or removed without notice in
|
||||
// /// any release. You should only use it directly in your code with extreme caution and knowing that
|
||||
// /// doing so can result in application failures when updating to a new Entity Framework Core release.
|
||||
// /// </summary>
|
||||
// public virtual object Execute(Expression expression)
|
||||
// => throw new NotSupportedException();
|
||||
|
||||
// /// <summary>
|
||||
// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
|
||||
// /// the same compatibility standards as public APIs. It may be changed or removed without notice in
|
||||
// /// any release. You should only use it directly in your code with extreme caution and knowing that
|
||||
// /// doing so can result in application failures when updating to a new Entity Framework Core release.
|
||||
// /// </summary>
|
||||
// public virtual TResult ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken = default)
|
||||
// {
|
||||
// var currentDbContext = GetCurrentDbContext();
|
||||
|
||||
// if (currentDbContext is IShardingDbContext shardingDbContext)
|
||||
// {
|
||||
// if (typeof(TResult).HasImplementedRawGeneric(typeof(IAsyncEnumerable<>)))
|
||||
// {
|
||||
// var constructors
|
||||
// = typeof(EnumerableQuery<>).GetTypeInfo().DeclaredConstructors
|
||||
// .Where(c => !c.IsStatic && c.IsPublic)
|
||||
// .ToArray();
|
||||
|
||||
// var parameters = constructors[0].GetParameters();
|
||||
// var parameterType = parameters[0].ParameterType;
|
||||
// Type type = typeof(EnumerableQuery<>);
|
||||
// type = type.MakeGenericType(ActualDbContextType);
|
||||
// Activator.CreateInstance(type);
|
||||
// }
|
||||
|
||||
// IQueryable<TResult> queryable = new EnumerableQuery<TResult>(expression);
|
||||
// var streamMergeContext = _streamMergeContextFactory.Create(queryable, shardingDbContext);
|
||||
|
||||
// var streamMergeEngine = AsyncEnumerableStreamMergeEngine<TResult>.Create<TResult>(streamMergeContext);
|
||||
// return streamMergeEngine.GetAsyncEnumerator();
|
||||
// }
|
||||
|
||||
// throw new ShardingCoreException("db context is not IShardingDbContext");
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -1,89 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using ShardingCore.Core;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
|
||||
namespace ShardingCore.Sharding.Query
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: Saturday, 14 August 2021 14:17:30
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class ShardingEntityQueryable<TResult> : IOrderedQueryable<TResult>,
|
||||
IAsyncEnumerable<TResult>,
|
||||
IListSource
|
||||
{
|
||||
private readonly IAsyncQueryProvider _queryProvider;
|
||||
|
||||
//private readonly DbContext _dbContext;
|
||||
|
||||
/// <summary>
|
||||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
|
||||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
|
||||
/// any release. You should only use it directly in your code with extreme caution and knowing that
|
||||
/// doing so can result in application failures when updating to a new Entity Framework Core release.
|
||||
/// </summary>
|
||||
public ShardingEntityQueryable(IAsyncQueryProvider queryProvider, IEntityType entityType)
|
||||
: this(queryProvider, new QueryRootExpression(queryProvider, entityType))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
|
||||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
|
||||
/// any release. You should only use it directly in your code with extreme caution and knowing that
|
||||
/// doing so can result in application failures when updating to a new Entity Framework Core release.
|
||||
/// </summary>
|
||||
public ShardingEntityQueryable(IAsyncQueryProvider queryProvider, Expression expression)
|
||||
{
|
||||
Check.NotNull(queryProvider, nameof(queryProvider));
|
||||
Check.NotNull(expression, nameof(expression));
|
||||
//if (queryProvider is ShardingEntityQueryProvider shardingEntityQueryProvider)
|
||||
//{
|
||||
// _dbContext = shardingEntityQueryProvider.GetCurrentDbContext().Context;
|
||||
//}
|
||||
|
||||
_queryProvider = queryProvider;
|
||||
Expression = expression;
|
||||
}
|
||||
|
||||
public IEnumerator<TResult> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
public IAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return _queryProvider.ExecuteAsync<IAsyncEnumerable<TResult>>(Expression).GetAsyncEnumerator(cancellationToken);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public Type ElementType => typeof(TResult);
|
||||
public Expression Expression { get; }
|
||||
public IQueryProvider Provider => _queryProvider;
|
||||
|
||||
public IList GetList()
|
||||
{
|
||||
throw new NotSupportedException(CoreStrings.DataBindingWithIListSource);
|
||||
}
|
||||
|
||||
public bool ContainsListCollection => false;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ShardingCore.Sharding
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/17 21:03:03
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class ShardingTempInternalDbSet<TEntity> :
|
||||
IQueryable<TEntity>,
|
||||
IEnumerable<TEntity>,
|
||||
IEnumerable,
|
||||
IQueryable where TEntity:class
|
||||
{
|
||||
private IQueryable<TEntity> _queryable;
|
||||
public ShardingTempInternalDbSet(EnumerableQuery<TEntity> queryable)
|
||||
{
|
||||
_queryable = queryable.AsQueryable();
|
||||
}
|
||||
public IEnumerator<TEntity> GetEnumerator()
|
||||
{
|
||||
return _queryable.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public Type ElementType => _queryable.ElementType;
|
||||
public Expression Expression => _queryable.Expression;
|
||||
public IQueryProvider Provider => _queryable.Provider;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ShardingCore.Core.ShardingAccessors;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine;
|
||||
using ShardingCore.DbContexts;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding.Enumerators
|
||||
namespace ShardingCore.Sharding
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/19 8:08:50
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public abstract class AbstractEnsureMethodCallConstantInMemoryAsyncMergeEngine<TEntity, TResult> : AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity, TResult>
|
||||
{
|
||||
private readonly MethodCallExpression _methodCallExpression;
|
||||
private readonly TEntity _constantItem;
|
||||
|
||||
protected AbstractEnsureMethodCallConstantInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
_methodCallExpression = methodCallExpression;
|
||||
var secondExpression = GetSecondExpression();
|
||||
if (!(secondExpression is ConstantExpression constantExpression))
|
||||
{
|
||||
throw new ShardingCoreException($"not found constant {methodCallExpression.Print()}");
|
||||
}
|
||||
_constantItem = (TEntity)constantExpression.Value;
|
||||
}
|
||||
protected override IQueryable<TEntity> ProcessSecondExpression(IQueryable<TEntity> queryable, Expression secondExpression)
|
||||
{
|
||||
if (!(secondExpression is ConstantExpression))
|
||||
{
|
||||
throw new InvalidOperationException(_methodCallExpression.Print());
|
||||
}
|
||||
|
||||
return queryable;
|
||||
}
|
||||
|
||||
protected TEntity GetConstantItem()
|
||||
{
|
||||
return _constantItem;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
|
@ -18,19 +14,19 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public abstract class AbstractEnsureMethodCallSelectorInMemoryAsyncMergeEngine<TEntity,TResult>: AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity, TResult>
|
||||
public abstract class AbstractEnsureMethodCallSelectorInMemoryAsyncMergeEngine<TEntity,TResult>: AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity, TResult>
|
||||
{
|
||||
|
||||
protected AbstractEnsureMethodCallSelectorInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
}
|
||||
|
||||
public override IQueryable EFQueryAfterFilter(IQueryable<TEntity> queryable)
|
||||
public override IQueryable EFQueryAfterFilter<TResult1>(IQueryable<TEntity> queryable)
|
||||
{
|
||||
var secondExpression = GetSecondExpression();
|
||||
if (secondExpression != null)
|
||||
{
|
||||
if(secondExpression is UnaryExpression unaryExpression&&unaryExpression.Operand is LambdaExpression lambdaExpression&&lambdaExpression is Expression<Func<TEntity, TResult>> selector)
|
||||
if (secondExpression is UnaryExpression unaryExpression && unaryExpression.Operand is LambdaExpression lambdaExpression && lambdaExpression is Expression<Func<TEntity, TResult>> selector)
|
||||
{
|
||||
return queryable.Select(selector);
|
||||
}
|
||||
|
@ -40,5 +36,11 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
|||
}
|
||||
return queryable;
|
||||
}
|
||||
|
||||
protected override IQueryable<TEntity> ProcessSecondExpression(IQueryable<TEntity> _queryable, Expression secondExpression)
|
||||
{
|
||||
return _queryable;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/19 8:22:19
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public abstract class AbstractEnsureMethodCallWhereInMemoryAsyncMergeEngine<TEntity, TResult> : AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity, TResult>
|
||||
{
|
||||
private readonly MethodCallExpression _methodCallExpression;
|
||||
|
||||
public AbstractEnsureMethodCallWhereInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
_methodCallExpression = methodCallExpression;
|
||||
}
|
||||
|
||||
protected override IQueryable<TEntity> ProcessSecondExpression(IQueryable<TEntity> queryable, Expression secondExpression)
|
||||
{
|
||||
if (secondExpression is UnaryExpression where && where.Operand is LambdaExpression lambdaExpression && lambdaExpression is Expression<Func<TEntity, bool>> predicate)
|
||||
{
|
||||
return queryable.Where(predicate);
|
||||
}
|
||||
throw new InvalidOperationException(_methodCallExpression.Print());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,60 +18,9 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
|||
*/
|
||||
public abstract class AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity, TResult> : AbstractInMemoryAsyncMergeEngine<TEntity>,IEnsureAsyncMergeResult<TResult>
|
||||
{
|
||||
private readonly MethodCallExpression _methodCallExpression;
|
||||
private readonly StreamMergeContext<TEntity> _mergeContext;
|
||||
private readonly IQueryable<TEntity> _queryable;
|
||||
private readonly Expression _secondExpression;
|
||||
|
||||
public AbstractEnsureMethodCallInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext)
|
||||
protected AbstractEnsureMethodCallInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
_methodCallExpression = methodCallExpression;
|
||||
var expression = methodCallExpression.Arguments.FirstOrDefault(o => typeof(IQueryable).IsAssignableFrom(o.Type)) ?? throw new InvalidOperationException(methodCallExpression.Print());
|
||||
_queryable = new EnumerableQuery<TEntity>(expression);
|
||||
_secondExpression = methodCallExpression.Arguments.FirstOrDefault(o => !typeof(IQueryable).IsAssignableFrom(o.Type));
|
||||
|
||||
if (_secondExpression != null)
|
||||
{
|
||||
if (_secondExpression is UnaryExpression where)
|
||||
{
|
||||
if(where.Operand is LambdaExpression lambdaExpression&& lambdaExpression is Expression<Func<TEntity, bool>> predicate)
|
||||
{
|
||||
_queryable = _queryable.Where(predicate);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException(methodCallExpression.Print());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (methodCallExpression.Arguments.Count == 2)
|
||||
throw new InvalidOperationException(methodCallExpression.Print());
|
||||
}
|
||||
|
||||
_mergeContext = ShardingContainer.GetService<IStreamMergeContextFactory>().Create(_queryable, shardingDbContext);
|
||||
}
|
||||
|
||||
public abstract Task<TResult> MergeResultAsync(CancellationToken cancellationToken = new CancellationToken());
|
||||
|
||||
protected override StreamMergeContext<TEntity> GetStreamMergeContext()
|
||||
{
|
||||
return _mergeContext;
|
||||
}
|
||||
protected IQueryable<TEntity> GetQueryable()
|
||||
{
|
||||
return _queryable;
|
||||
}
|
||||
|
||||
protected MethodCallExpression GetMethodCallExpression()
|
||||
{
|
||||
return _methodCallExpression;
|
||||
}
|
||||
|
||||
protected Expression GetSecondExpression()
|
||||
{
|
||||
return _secondExpression;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/19 8:29:05
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public abstract class AbstractGenericMethodCallSelectorInMemoryAsyncMergeEngine<TEntity>:AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public AbstractGenericMethodCallSelectorInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
}
|
||||
|
||||
public override IQueryable EFQueryAfterFilter<TResult>(IQueryable<TEntity> queryable)
|
||||
{
|
||||
var secondExpression = GetSecondExpression();
|
||||
if (secondExpression != null)
|
||||
{
|
||||
if (secondExpression is UnaryExpression unaryExpression && unaryExpression.Operand is LambdaExpression lambdaExpression && lambdaExpression is Expression<Func<TEntity, TResult>> selector)
|
||||
{
|
||||
return queryable.Select(selector);
|
||||
}
|
||||
|
||||
|
||||
throw new ShardingCoreException($"expression is not selector:{secondExpression.Print()}");
|
||||
}
|
||||
return queryable;
|
||||
}
|
||||
|
||||
protected override IQueryable<TEntity> ProcessSecondExpression(IQueryable<TEntity> _queryable, Expression secondExpression)
|
||||
{
|
||||
return _queryable;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/19 8:42:02
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public abstract class AbstractGenericMethodCallWhereInMemoryAsyncMergeEngine<TEntity>: AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
private readonly MethodCallExpression _methodCallExpression;
|
||||
|
||||
public AbstractGenericMethodCallWhereInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
_methodCallExpression = methodCallExpression;
|
||||
}
|
||||
|
||||
protected override IQueryable<TEntity> ProcessSecondExpression(IQueryable<TEntity> queryable, Expression secondExpression)
|
||||
{
|
||||
if (secondExpression is UnaryExpression where)
|
||||
{
|
||||
if (where.Operand is LambdaExpression lambdaExpression && lambdaExpression is Expression<Func<TEntity, bool>> predicate)
|
||||
{
|
||||
return queryable.Where(predicate);
|
||||
}
|
||||
}
|
||||
throw new InvalidOperationException(_methodCallExpression.Print());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -19,39 +19,11 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
|||
public abstract class AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity> : AbstractInMemoryAsyncMergeEngine<TEntity>, IGenericAsyncMergeResult
|
||||
{
|
||||
|
||||
private readonly StreamMergeContext<TEntity> _mergeContext;
|
||||
private readonly IQueryable<TEntity> _queryable;
|
||||
|
||||
public AbstractGenericMethodCallInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext)
|
||||
protected AbstractGenericMethodCallInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
var expression = methodCallExpression.Arguments.FirstOrDefault(o => typeof(IQueryable).IsAssignableFrom(o.Type)) ?? throw new InvalidOperationException(methodCallExpression.Print());
|
||||
_queryable = new EnumerableQuery<TEntity>(expression);
|
||||
var predicate = methodCallExpression.Arguments.FirstOrDefault(o => o is UnaryExpression);
|
||||
|
||||
if (predicate != null)
|
||||
{
|
||||
|
||||
_queryable = _queryable.Where((Expression<Func<TEntity, bool>>)((UnaryExpression)predicate).Operand);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (methodCallExpression.Arguments.Count == 2)
|
||||
throw new InvalidOperationException(methodCallExpression.Print());
|
||||
}
|
||||
|
||||
_mergeContext = ShardingContainer.GetService<IStreamMergeContextFactory>().Create(_queryable, shardingDbContext);
|
||||
}
|
||||
|
||||
public abstract Task<TResult> MergeResultAsync<TResult>(
|
||||
CancellationToken cancellationToken = new CancellationToken());
|
||||
|
||||
protected override StreamMergeContext<TEntity> GetStreamMergeContext()
|
||||
{
|
||||
return _mergeContext;
|
||||
}
|
||||
protected IQueryable<TEntity> GetQueryable()
|
||||
{
|
||||
return _queryable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
||||
{
|
||||
|
@ -15,13 +19,34 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public abstract class AbstractInMemoryAsyncMergeEngine<T>
|
||||
public abstract class AbstractInMemoryAsyncMergeEngine<TEntity>: IInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取流失合并上下文
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract StreamMergeContext<T> GetStreamMergeContext();
|
||||
private readonly MethodCallExpression _methodCallExpression;
|
||||
private readonly StreamMergeContext<TEntity> _mergeContext;
|
||||
private readonly IQueryable<TEntity> _queryable;
|
||||
private readonly Expression _secondExpression;
|
||||
|
||||
public AbstractInMemoryAsyncMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext)
|
||||
{
|
||||
_methodCallExpression = methodCallExpression;
|
||||
var expression = methodCallExpression.Arguments.FirstOrDefault(o => typeof(IQueryable).IsAssignableFrom(o.Type)) ?? throw new InvalidOperationException(methodCallExpression.Print());
|
||||
_queryable = new EnumerableQuery<TEntity>(expression);
|
||||
_secondExpression = methodCallExpression.Arguments.FirstOrDefault(o => !typeof(IQueryable).IsAssignableFrom(o.Type));
|
||||
|
||||
if (_secondExpression != null)
|
||||
{
|
||||
_queryable = ProcessSecondExpression(_queryable, _secondExpression);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (methodCallExpression.Arguments.Count == 2)
|
||||
throw new InvalidOperationException(methodCallExpression.Print());
|
||||
}
|
||||
|
||||
_mergeContext = ShardingContainer.GetService<IStreamMergeContextFactory>().Create(_queryable, shardingDbContext);
|
||||
}
|
||||
|
||||
protected abstract IQueryable<TEntity> ProcessSecondExpression(IQueryable<TEntity> queryable, Expression secondExpression);
|
||||
|
||||
public async Task<List<TResult>> ExecuteAsync<TResult>(Func<IQueryable, Task<TResult>> efQuery,CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
|
@ -44,9 +69,9 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
|||
//scope.ShardingAccessor.ShardingContext = shardingContext;
|
||||
|
||||
var shardingDbContext = GetStreamMergeContext().CreateDbContext(tail);
|
||||
var newQueryable = (IQueryable<T>)GetStreamMergeContext().GetReWriteQueryable()
|
||||
var newQueryable = (IQueryable<TEntity>)GetStreamMergeContext().GetReWriteQueryable()
|
||||
.ReplaceDbContextQueryable(shardingDbContext);
|
||||
var newFilterQueryable=EFQueryAfterFilter(newQueryable);
|
||||
var newFilterQueryable=EFQueryAfterFilter<TResult>(newQueryable);
|
||||
var query = await efQuery(newFilterQueryable);
|
||||
return query;
|
||||
//}
|
||||
|
@ -62,10 +87,29 @@ namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
|||
return (await Task.WhenAll(enumeratorTasks)).ToList();
|
||||
}
|
||||
|
||||
public virtual IQueryable EFQueryAfterFilter(IQueryable<T> queryable)
|
||||
public virtual IQueryable EFQueryAfterFilter<TResult>(IQueryable<TEntity> queryable)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
public StreamMergeContext<TEntity> GetStreamMergeContext()
|
||||
{
|
||||
return _mergeContext;
|
||||
}
|
||||
public IQueryable<TEntity> GetQueryable()
|
||||
{
|
||||
return _queryable;
|
||||
}
|
||||
|
||||
protected MethodCallExpression GetMethodCallExpression()
|
||||
{
|
||||
return _methodCallExpression;
|
||||
}
|
||||
|
||||
protected Expression GetSecondExpression()
|
||||
{
|
||||
return _secondExpression;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.Abstractions
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/19 8:58:47
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public interface IInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
StreamMergeContext<TEntity> GetStreamMergeContext();
|
||||
Task<List<TResult>> ExecuteAsync<TResult>(Func<IQueryable, Task<TResult>> efQuery,
|
||||
CancellationToken cancellationToken = new CancellationToken());
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ using ShardingCore.Exceptions;
|
|||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.AggregateMergeEngines
|
||||
{
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.AggregateMergeEngines
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/18 22:30:07
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
class ContainsAsyncInMemoryMergeEngine
|
||||
{
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.AggregateMergeEngines
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines.AggregateMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class MaxAsyncInMemoryMergeEngine<TEntity>:AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
public class MaxAsyncInMemoryMergeEngine<TEntity>: AbstractGenericMethodCallSelectorInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public MaxAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.AggregateMergeEngines
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines.AggregateMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class MinAsyncInMemoryMergeEngine<TEntity> : AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
public class MinAsyncInMemoryMergeEngine<TEntity> : AbstractGenericMethodCallSelectorInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public MinAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@ using ShardingCore.Exceptions;
|
|||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines.AggregateMergeEngines
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
|||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -20,7 +21,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class AllAsyncInMemoryMergeEngine<TEntity> : AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity, bool>
|
||||
public class AllAsyncInMemoryMergeEngine<TEntity> : AbstractEnsureMethodCallWhereInMemoryAsyncMergeEngine<TEntity, bool>
|
||||
{
|
||||
public AllAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
|||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -20,7 +21,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class AnyAsyncInMemoryMergeEngine<TEntity> : AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity,bool>
|
||||
public class AnyAsyncInMemoryMergeEngine<TEntity> : AbstractEnsureMethodCallWhereInMemoryAsyncMergeEngine<TEntity,bool>
|
||||
{
|
||||
public AnyAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
@ -29,7 +30,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
{
|
||||
var result = await base.ExecuteAsync(async queryable => await ((IQueryable<TEntity>)queryable).AnyAsync(cancellationToken), cancellationToken);
|
||||
|
||||
return result.Any(o=>o);
|
||||
return result.Any(o => o);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/8/18 22:30:07
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class ContainsAsyncInMemoryMergeEngine<TEntity>: AbstractEnsureMethodCallConstantInMemoryAsyncMergeEngine<TEntity,bool>
|
||||
{
|
||||
public ContainsAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<bool> MergeResultAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
var result = await base.ExecuteAsync(async queryable => await ((IQueryable<TEntity>)queryable).ContainsAsync(GetConstantItem(), cancellationToken), cancellationToken);
|
||||
|
||||
return result.Any(o => o);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,17 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -22,7 +16,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class CountAsyncInMemoryMergeEngine<TEntity> : AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity,int>
|
||||
public class CountAsyncInMemoryMergeEngine<TEntity> : AbstractEnsureMethodCallWhereInMemoryAsyncMergeEngine<TEntity,int>
|
||||
{
|
||||
public CountAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class FirstAsyncInMemoryMergeEngine<TEntity>:AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
public class FirstAsyncInMemoryMergeEngine<TEntity>: AbstractGenericMethodCallWhereInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public FirstAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ using ShardingCore.Extensions;
|
|||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -22,7 +23,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class FirstOrDefaultAsyncInMemoryMergeEngine<TEntity> :AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
public class FirstOrDefaultAsyncInMemoryMergeEngine<TEntity> : AbstractGenericMethodCallWhereInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public FirstOrDefaultAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class LastAsyncInMemoryMergeEngine<TEntity>:AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
public class LastAsyncInMemoryMergeEngine<TEntity>: AbstractGenericMethodCallWhereInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public LastAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class LastOrDefaultAsyncInMemoryMergeEngine<TEntity>:AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
public class LastOrDefaultAsyncInMemoryMergeEngine<TEntity>: AbstractGenericMethodCallWhereInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public LastOrDefaultAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@ using ShardingCore.Exceptions;
|
|||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.Enumerators;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractEnsureExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -21,7 +22,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class LongCountAsyncInMemoryMergeEngine<TEntity> : AbstractEnsureMethodCallInMemoryAsyncMergeEngine<TEntity,long>
|
||||
public class LongCountAsyncInMemoryMergeEngine<TEntity> : AbstractEnsureMethodCallWhereInMemoryAsyncMergeEngine<TEntity,long>
|
||||
{
|
||||
public LongCountAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class SingleAsyncInMemoryMergeEngine<TEntity>:AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
public class SingleAsyncInMemoryMergeEngine<TEntity>: AbstractGenericMethodCallWhereInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public SingleAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions;
|
||||
using ShardingCore.Sharding.StreamMergeEngines.Abstractions.AbstractGenericExpressionMergeEngines;
|
||||
|
||||
namespace ShardingCore.Sharding.StreamMergeEngines
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ namespace ShardingCore.Sharding.StreamMergeEngines
|
|||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class SingleOrDefaultAsyncInMemoryMergeEngine<TEntity>:AbstractGenericMethodCallInMemoryAsyncMergeEngine<TEntity>
|
||||
public class SingleOrDefaultAsyncInMemoryMergeEngine<TEntity>: AbstractGenericMethodCallWhereInMemoryAsyncMergeEngine<TEntity>
|
||||
{
|
||||
public SingleOrDefaultAsyncInMemoryMergeEngine(MethodCallExpression methodCallExpression, IShardingDbContext shardingDbContext) : base(methodCallExpression, shardingDbContext)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue