移除asroute和readonly和writeonly后续支持
This commit is contained in:
parent
aab1cab532
commit
d0047ea21a
|
@ -22,12 +22,12 @@ namespace ShardingCore.Extensions.ShardingQueryableExtensions
|
|||
internal static readonly MethodInfo NotSupportMethodInfo
|
||||
= typeof(EntityFrameworkShardingQueryableExtension).GetTypeInfo().GetDeclaredMethods(nameof(NotSupport)).Single();
|
||||
|
||||
internal static readonly MethodInfo AsRouteMethodInfo
|
||||
= typeof(EntityFrameworkShardingQueryableExtension)
|
||||
.GetTypeInfo()
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Static |BindingFlags.NonPublic)
|
||||
.Where(m => m.Name == nameof(AsRoute))
|
||||
.Single(m => m.GetParameters().Any(p => p.ParameterType == typeof(ShardingQueryableAsRouteOptions)));
|
||||
//internal static readonly MethodInfo AsRouteMethodInfo
|
||||
// = typeof(EntityFrameworkShardingQueryableExtension)
|
||||
// .GetTypeInfo()
|
||||
// .GetMethods(BindingFlags.Instance | BindingFlags.Static |BindingFlags.NonPublic)
|
||||
// .Where(m => m.Name == nameof(AsRoute))
|
||||
// .Single(m => m.GetParameters().Any(p => p.ParameterType == typeof(ShardingQueryableAsRouteOptions)));
|
||||
|
||||
internal static readonly MethodInfo UseConnectionModeMethodInfo
|
||||
= typeof(EntityFrameworkShardingQueryableExtension)
|
||||
|
@ -36,12 +36,12 @@ namespace ShardingCore.Extensions.ShardingQueryableExtensions
|
|||
.Where(m => m.Name == nameof(UseConnectionMode))
|
||||
.Single(m => m.GetParameters().Any(p => p.ParameterType == typeof(ShardingQueryableUseConnectionModeOptions)));
|
||||
|
||||
internal static readonly MethodInfo ReadWriteSeparationMethodInfo
|
||||
= typeof(EntityFrameworkShardingQueryableExtension)
|
||||
.GetTypeInfo()
|
||||
.GetMethods()
|
||||
.Where(m => m.Name == nameof(ReadWriteSeparation))
|
||||
.Single(m => m.GetParameters().Any(p => p.ParameterType == typeof(bool)));
|
||||
//internal static readonly MethodInfo ReadWriteSeparationMethodInfo
|
||||
// = typeof(EntityFrameworkShardingQueryableExtension)
|
||||
// .GetTypeInfo()
|
||||
// .GetMethods()
|
||||
// .Where(m => m.Name == nameof(ReadWriteSeparation))
|
||||
// .Single(m => m.GetParameters().Any(p => p.ParameterType == typeof(bool)));
|
||||
|
||||
/// <summary>
|
||||
/// 标记当前操作是不支持分片的可以自行才用union all
|
||||
|
@ -63,35 +63,35 @@ namespace ShardingCore.Extensions.ShardingQueryableExtensions
|
|||
: source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启提示路由的前提下手动指定表、手动指定数据源
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="routeConfigure"></param>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<TEntity> AsRoute<TEntity>(this IQueryable<TEntity> source, Action<ShardingRouteContext> routeConfigure)
|
||||
{
|
||||
Check.NotNull(source, nameof(source));
|
||||
Check.NotNull(routeConfigure, nameof(routeConfigure));
|
||||
var shardingQueryableAsRouteOptions = new ShardingQueryableAsRouteOptions(routeConfigure);
|
||||
///// <summary>
|
||||
///// 开启提示路由的前提下手动指定表、手动指定数据源
|
||||
///// </summary>
|
||||
///// <param name="source"></param>
|
||||
///// <param name="routeConfigure"></param>
|
||||
///// <typeparam name="TEntity"></typeparam>
|
||||
///// <returns></returns>
|
||||
//public static IQueryable<TEntity> AsRoute<TEntity>(this IQueryable<TEntity> source, Action<ShardingRouteContext> routeConfigure)
|
||||
//{
|
||||
// Check.NotNull(source, nameof(source));
|
||||
// Check.NotNull(routeConfigure, nameof(routeConfigure));
|
||||
// var shardingQueryableAsRouteOptions = new ShardingQueryableAsRouteOptions(routeConfigure);
|
||||
|
||||
return source.AsRoute(shardingQueryableAsRouteOptions);
|
||||
}
|
||||
internal static IQueryable<TEntity> AsRoute<TEntity>(this IQueryable<TEntity> source, ShardingQueryableAsRouteOptions shardingQueryableAsRouteOptions)
|
||||
{
|
||||
Check.NotNull(source, nameof(source));
|
||||
// return source.AsRoute(shardingQueryableAsRouteOptions);
|
||||
//}
|
||||
//internal static IQueryable<TEntity> AsRoute<TEntity>(this IQueryable<TEntity> source, ShardingQueryableAsRouteOptions shardingQueryableAsRouteOptions)
|
||||
//{
|
||||
// Check.NotNull(source, nameof(source));
|
||||
|
||||
return
|
||||
source.Provider is EntityQueryProvider
|
||||
? source.Provider.CreateQuery<TEntity>(
|
||||
Expression.Call(
|
||||
(Expression)null,
|
||||
AsRouteMethodInfo.MakeGenericMethod(typeof(TEntity)),
|
||||
source.Expression,
|
||||
Expression.Constant(shardingQueryableAsRouteOptions)))
|
||||
: source;
|
||||
}
|
||||
// return
|
||||
// source.Provider is EntityQueryProvider
|
||||
// ? source.Provider.CreateQuery<TEntity>(
|
||||
// Expression.Call(
|
||||
// (Expression)null,
|
||||
// AsRouteMethodInfo.MakeGenericMethod(typeof(TEntity)),
|
||||
// source.Expression,
|
||||
// Expression.Constant(shardingQueryableAsRouteOptions)))
|
||||
// : source;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 设置连接而模式
|
||||
|
@ -126,49 +126,49 @@ namespace ShardingCore.Extensions.ShardingQueryableExtensions
|
|||
: source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 走读库
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<TEntity> ReadOnly<TEntity>(this IQueryable<TEntity> source)
|
||||
{
|
||||
return source.ReadWriteSeparation(true);
|
||||
}
|
||||
///// <summary>
|
||||
///// 走读库
|
||||
///// </summary>
|
||||
///// <param name="source"></param>
|
||||
///// <typeparam name="TEntity"></typeparam>
|
||||
///// <returns></returns>
|
||||
//public static IQueryable<TEntity> ReadOnly<TEntity>(this IQueryable<TEntity> source)
|
||||
//{
|
||||
// return source.ReadWriteSeparation(true);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 走写库
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<TEntity> WriteOnly<TEntity>(this IQueryable<TEntity> source)
|
||||
{
|
||||
return source.ReadWriteSeparation(false);
|
||||
}
|
||||
///// <summary>
|
||||
///// 走写库
|
||||
///// </summary>
|
||||
///// <param name="source"></param>
|
||||
///// <typeparam name="TEntity"></typeparam>
|
||||
///// <returns></returns>
|
||||
//public static IQueryable<TEntity> WriteOnly<TEntity>(this IQueryable<TEntity> source)
|
||||
//{
|
||||
// return source.ReadWriteSeparation(false);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义读写分离走什么库
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="routeReadConnect"></param>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<TEntity> ReadWriteSeparation<TEntity>(this IQueryable<TEntity> source, bool routeReadConnect)
|
||||
{
|
||||
Check.NotNull(source, nameof(source));
|
||||
var shardingQueryableReadWriteSeparationOptions = new ShardingQueryableReadWriteSeparationOptions(routeReadConnect);
|
||||
///// <summary>
|
||||
///// 自定义读写分离走什么库
|
||||
///// </summary>
|
||||
///// <param name="source"></param>
|
||||
///// <param name="routeReadConnect"></param>
|
||||
///// <typeparam name="TEntity"></typeparam>
|
||||
///// <returns></returns>
|
||||
//public static IQueryable<TEntity> ReadWriteSeparation<TEntity>(this IQueryable<TEntity> source, bool routeReadConnect)
|
||||
//{
|
||||
// Check.NotNull(source, nameof(source));
|
||||
// var shardingQueryableReadWriteSeparationOptions = new ShardingQueryableReadWriteSeparationOptions(routeReadConnect);
|
||||
|
||||
return
|
||||
source.Provider is EntityQueryProvider
|
||||
? source.Provider.CreateQuery<TEntity>(
|
||||
Expression.Call(
|
||||
(Expression)null,
|
||||
ReadWriteSeparationMethodInfo.MakeGenericMethod(typeof(TEntity)),
|
||||
source.Expression,
|
||||
Expression.Constant(shardingQueryableReadWriteSeparationOptions)))
|
||||
: source;
|
||||
}
|
||||
// return
|
||||
// source.Provider is EntityQueryProvider
|
||||
// ? source.Provider.CreateQuery<TEntity>(
|
||||
// Expression.Call(
|
||||
// (Expression)null,
|
||||
// ReadWriteSeparationMethodInfo.MakeGenericMethod(typeof(TEntity)),
|
||||
// source.Expression,
|
||||
// Expression.Constant(shardingQueryableReadWriteSeparationOptions)))
|
||||
// : source;
|
||||
//}
|
||||
}
|
||||
}
|
|
@ -65,10 +65,7 @@ namespace ShardingCore.Extensions
|
|||
supportShardingReadWrite.ReadWriteSeparationPriority = shardingReadWriteContext.DefaultPriority + 1;
|
||||
}
|
||||
}
|
||||
if (supportShardingReadWrite.ReadWriteSeparation!= readOnly)
|
||||
{
|
||||
supportShardingReadWrite.ReadWriteSeparation = readOnly;
|
||||
}
|
||||
supportShardingReadWrite.ReadWriteSeparation = readOnly;
|
||||
}
|
||||
public static void SetReadWriteSeparation(this ShardingReadWriteContext shardingReadWriteContext,int priority, bool readOnly)
|
||||
{
|
||||
|
|
|
@ -25,10 +25,10 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
var compileParameter = new CompileParameter(shardingDbContext,query);
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
|
||||
using (new CustomerQueryScope(compileParameter))
|
||||
{
|
||||
//using (new CustomerQueryScope(compileParameter))
|
||||
//{
|
||||
return _shardingTrackQueryExecutor.Execute<TResult>(queryCompilerContext);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,10 +40,10 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
var compileParameter = new CompileParameter(shardingDbContext,query);
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
|
||||
using (new CustomerQueryScope(compileParameter))
|
||||
{
|
||||
//using (new CustomerQueryScope(compileParameter))
|
||||
//{
|
||||
return _shardingTrackQueryExecutor.ExecuteAsync<TResult>(queryCompilerContext);
|
||||
}
|
||||
//}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -52,10 +52,10 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
{
|
||||
var compileParameter = new CompileParameter(shardingDbContext,query);
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
using (new CustomerQueryScope(compileParameter))
|
||||
{
|
||||
//using (new CustomerQueryScope(compileParameter))
|
||||
//{
|
||||
return _shardingTrackQueryExecutor.ExecuteAsync<TResult>(queryCompilerContext);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
public Task<TResult> ExecuteAsync<TResult>(IShardingDbContext shardingDbContext, Expression query,
|
||||
|
@ -63,10 +63,10 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
{
|
||||
var compileParameter = new CompileParameter(shardingDbContext,query);
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
using (new CustomerQueryScope(compileParameter))
|
||||
{
|
||||
//using (new CustomerQueryScope(compileParameter))
|
||||
//{
|
||||
return _shardingTrackQueryExecutor.ExecuteAsync<TResult>(queryCompilerContext, cancellationToken);
|
||||
}
|
||||
//}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -42,23 +42,24 @@ namespace ShardingCore.Sharding.Visitors.ShardingExtractParameters
|
|||
.Select(o => (ShardingQueryableUseConnectionModeOptions)o.Value)
|
||||
.Last();
|
||||
return Visit(node.Arguments[0]);
|
||||
}else if (genericMethodDefinition == EntityFrameworkShardingQueryableExtension.AsRouteMethodInfo)
|
||||
{
|
||||
shardingQueryableAsRouteOptions = node.Arguments
|
||||
.OfType<ConstantExpression>()
|
||||
.Where(o => o.Value is ShardingQueryableAsRouteOptions)
|
||||
.Select(o => (ShardingQueryableAsRouteOptions)o.Value)
|
||||
.Last();
|
||||
return Visit(node.Arguments[0]);
|
||||
}else if (genericMethodDefinition == EntityFrameworkShardingQueryableExtension.ReadWriteSeparationMethodInfo)
|
||||
{
|
||||
shardingQueryableReadWriteSeparationOptions = node.Arguments
|
||||
.OfType<ConstantExpression>()
|
||||
.Where(o => o.Value is ShardingQueryableReadWriteSeparationOptions)
|
||||
.Select(o => (ShardingQueryableReadWriteSeparationOptions)o.Value)
|
||||
.Last();
|
||||
return Visit(node.Arguments[0]);
|
||||
}
|
||||
//else if (genericMethodDefinition == EntityFrameworkShardingQueryableExtension.AsRouteMethodInfo)
|
||||
//{
|
||||
// shardingQueryableAsRouteOptions = node.Arguments
|
||||
// .OfType<ConstantExpression>()
|
||||
// .Where(o => o.Value is ShardingQueryableAsRouteOptions)
|
||||
// .Select(o => (ShardingQueryableAsRouteOptions)o.Value)
|
||||
// .Last();
|
||||
// return Visit(node.Arguments[0]);
|
||||
//}else if (genericMethodDefinition == EntityFrameworkShardingQueryableExtension.ReadWriteSeparationMethodInfo)
|
||||
//{
|
||||
// shardingQueryableReadWriteSeparationOptions = node.Arguments
|
||||
// .OfType<ConstantExpression>()
|
||||
// .Where(o => o.Value is ShardingQueryableReadWriteSeparationOptions)
|
||||
// .Select(o => (ShardingQueryableReadWriteSeparationOptions)o.Value)
|
||||
// .Last();
|
||||
// return Visit(node.Arguments[0]);
|
||||
//}
|
||||
}
|
||||
return base.VisitMethodCall(node);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue