添加notsupport并且支持asroute方法,发布x.4.1.4
This commit is contained in:
parent
f672eb9446
commit
6d50d562eb
|
@ -1,9 +1,9 @@
|
|||
:start
|
||||
::定义版本
|
||||
set EFCORE2=2.4.1.02
|
||||
set EFCORE3=3.4.1.02
|
||||
set EFCORE5=5.4.1.02
|
||||
set EFCORE6=6.4.1.02
|
||||
set EFCORE2=2.4.1.04
|
||||
set EFCORE3=3.4.1.04
|
||||
set EFCORE5=5.4.1.04
|
||||
set EFCORE6=6.4.1.04
|
||||
|
||||
::删除所有bin与obj下的文件
|
||||
@echo off
|
||||
|
|
|
@ -39,7 +39,6 @@ namespace Samples.AutoByDate.SqlServer
|
|||
o.AddShardingTableRoute<SysUserLogByDayVirtualTableRoute>();
|
||||
o.AddShardingTableRoute<SysUserLog1ByDayVirtualTableRoute>();
|
||||
o.AddShardingTableRoute<TestLogWeekVirtualRoute>();
|
||||
o.UseInnerDbContextConfigure();
|
||||
})
|
||||
.AddConfig(sp =>
|
||||
{
|
||||
|
|
|
@ -18,7 +18,8 @@ namespace ShardingCore.Extensions
|
|||
/// <returns></returns>
|
||||
public static bool HasCustomerQuery(this ICompileParameter compileParameter)
|
||||
{
|
||||
return compileParameter.ReadOnly().HasValue || compileParameter.GetAsRoute() != null;
|
||||
//compileParameter.ReadOnly().HasValue || compileParameter.GetAsRoute() != null;
|
||||
return compileParameter.GetAsRoute() != null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,15 +19,15 @@ namespace ShardingCore.Extensions.ShardingQueryableExtensions
|
|||
/// </summary>
|
||||
public static class EntityFrameworkShardingQueryableExtension
|
||||
{
|
||||
|
||||
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)
|
||||
|
@ -52,7 +52,6 @@ namespace ShardingCore.Extensions.ShardingQueryableExtensions
|
|||
public static IQueryable<TEntity> NotSupport<TEntity>(this IQueryable<TEntity> source)
|
||||
{
|
||||
Check.NotNull(source, nameof(source));
|
||||
|
||||
return
|
||||
source.Provider is EntityQueryProvider
|
||||
? source.Provider.CreateQuery<TEntity>(
|
||||
|
@ -63,35 +62,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>
|
||||
/// 设置连接而模式
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using ShardingCore.Core;
|
||||
using ShardingCore.Core.QueryRouteManagers;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using ShardingCore.Core;
|
||||
using ShardingCore.Core.QueryRouteManagers;
|
||||
|
|
|
@ -17,7 +17,6 @@ namespace ShardingCore.ShardingExecutors
|
|||
internal class CustomerQueryScope:IDisposable
|
||||
{
|
||||
private readonly ShardingRouteScope _shardingRouteScope;
|
||||
private readonly CustomerReadWriteScope _customerReadWriteScope;
|
||||
private readonly bool _hasCustomerQuery;
|
||||
public CustomerQueryScope(ICompileParameter compileParameter)
|
||||
{
|
||||
|
@ -32,11 +31,6 @@ namespace ShardingCore.ShardingExecutors
|
|||
asRoute.Invoke(shardingRouteManager.Current);
|
||||
}
|
||||
|
||||
var readOnly = compileParameter.ReadOnly();
|
||||
if (readOnly.HasValue)
|
||||
{
|
||||
_customerReadWriteScope = new CustomerReadWriteScope(compileParameter.GetShardingDbContext(), readOnly.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
|
@ -44,7 +38,6 @@ namespace ShardingCore.ShardingExecutors
|
|||
if (_hasCustomerQuery)
|
||||
{
|
||||
_shardingRouteScope?.Dispose();
|
||||
_customerReadWriteScope?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
public TResult Execute<TResult>(IShardingDbContext shardingDbContext, Expression query)
|
||||
{
|
||||
var compileParameter = new CompileParameter(shardingDbContext,query);
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
|
||||
//using (new CustomerQueryScope(compileParameter))
|
||||
//{
|
||||
return _shardingTrackQueryExecutor.Execute<TResult>(queryCompilerContext);
|
||||
//}
|
||||
using (new CustomerQueryScope(compileParameter))
|
||||
{
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
return _shardingTrackQueryExecutor.Execute<TResult>(queryCompilerContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,12 +38,12 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
var compileParameter = new CompileParameter(shardingDbContext,query);
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
|
||||
//using (new CustomerQueryScope(compileParameter))
|
||||
//{
|
||||
using (new CustomerQueryScope(compileParameter))
|
||||
{
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
return _shardingTrackQueryExecutor.ExecuteAsync<TResult>(queryCompilerContext);
|
||||
//}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -51,22 +51,22 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
public IAsyncEnumerable<TResult> ExecuteAsync<TResult>(IShardingDbContext shardingDbContext, Expression query)
|
||||
{
|
||||
var compileParameter = new CompileParameter(shardingDbContext,query);
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
//using (new CustomerQueryScope(compileParameter))
|
||||
//{
|
||||
using (new CustomerQueryScope(compileParameter))
|
||||
{
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
return _shardingTrackQueryExecutor.ExecuteAsync<TResult>(queryCompilerContext);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public Task<TResult> ExecuteAsync<TResult>(IShardingDbContext shardingDbContext, Expression query,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var compileParameter = new CompileParameter(shardingDbContext,query);
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
//using (new CustomerQueryScope(compileParameter))
|
||||
//{
|
||||
using (new CustomerQueryScope(compileParameter))
|
||||
{
|
||||
var queryCompilerContext = _queryCompilerContextFactory.Create(compileParameter);
|
||||
return _shardingTrackQueryExecutor.ExecuteAsync<TResult>(queryCompilerContext, cancellationToken);
|
||||
//}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -43,15 +43,16 @@ namespace ShardingCore.Sharding.Visitors.ShardingExtractParameters
|
|||
.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)
|
||||
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>()
|
||||
|
|
|
@ -21,6 +21,7 @@ using ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine;
|
|||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Extensions.ShardingPageExtensions;
|
||||
using ShardingCore.Extensions.ShardingQueryableExtensions;
|
||||
using ShardingCore.Helpers;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
|
@ -1316,6 +1317,7 @@ namespace ShardingCore.Test
|
|||
Assert.Equal(300, countAsync1);
|
||||
}
|
||||
Assert.Null(_shardingRouteManager.Current);
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public async Task LogYearLongShardingPage()
|
||||
|
@ -1588,6 +1590,42 @@ namespace ShardingCore.Test
|
|||
Assert.Equal(10, page1.Data.Count);
|
||||
Assert.Equal(300, page1.Total);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AsRouteTest()
|
||||
{
|
||||
var countAsync3 = await _virtualDbContext.Set<LogMonthLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogMonthLong>("202104");
|
||||
}).CountAsync();
|
||||
Assert.Equal(30, countAsync3);
|
||||
var countAsync2 = await _virtualDbContext.Set<LogYearLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogYearLong>("2021");
|
||||
}).CountAsync();
|
||||
Assert.Equal(300, countAsync2);
|
||||
|
||||
var countAsync4 = await _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogWeekTimeLong>("20210419_25");
|
||||
}).CountAsync();
|
||||
Assert.Equal(7, countAsync4);
|
||||
|
||||
var countAsync5 = await _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintTail<LogWeekTimeLong>("20210419_25", "20210426_02");
|
||||
}).CountAsync();
|
||||
Assert.Equal(14, countAsync5);
|
||||
|
||||
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var sum = await _virtualDbContext.Set<Order>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintDataSource<Order>("C");
|
||||
})
|
||||
.Where(o => o.CreateTime == fiveBegin).Select(o => o.Money).SumAsync();
|
||||
Assert.Equal(0, sum);
|
||||
}
|
||||
// [Fact]
|
||||
// public async Task Group_API_Test()
|
||||
// {
|
||||
|
|
|
@ -25,6 +25,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using ShardingCore.Extensions.ShardingQueryableExtensions;
|
||||
using Xunit;
|
||||
|
||||
namespace ShardingCore.Test
|
||||
|
@ -1422,6 +1423,41 @@ namespace ShardingCore.Test
|
|||
Assert.Equal(10, page1.Data.Count);
|
||||
Assert.Equal(300, page1.Total);
|
||||
}
|
||||
[Fact]
|
||||
public void AsRouteTest()
|
||||
{
|
||||
var countAsync3 = _virtualDbContext.Set<LogMonthLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogMonthLong>("202104");
|
||||
}).Count();
|
||||
Assert.Equal(30, countAsync3);
|
||||
var countAsync2 = _virtualDbContext.Set<LogYearLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogYearLong>("2021");
|
||||
}).Count();
|
||||
Assert.Equal(300, countAsync2);
|
||||
|
||||
var countAsync4 = _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogWeekTimeLong>("20210419_25");
|
||||
}).Count();
|
||||
Assert.Equal(7, countAsync4);
|
||||
|
||||
var countAsync5 = _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintTail<LogWeekTimeLong>("20210419_25", "20210426_02");
|
||||
}).Count();
|
||||
Assert.Equal(14, countAsync5);
|
||||
|
||||
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var sum = _virtualDbContext.Set<Order>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintDataSource<Order>("C");
|
||||
})
|
||||
.Where(o => o.CreateTime == fiveBegin).Select(o => o.Money).Sum();
|
||||
Assert.Equal(0, sum);
|
||||
}
|
||||
// [Fact]
|
||||
// public void Group_API_Test()
|
||||
// {
|
||||
|
|
|
@ -18,6 +18,7 @@ using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
|||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Extensions.ShardingPageExtensions;
|
||||
using ShardingCore.Extensions.ShardingQueryableExtensions;
|
||||
using ShardingCore.Helpers;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
|
@ -1496,6 +1497,41 @@ namespace ShardingCore.Test2x
|
|||
Assert.Equal(10, page1.Data.Count);
|
||||
Assert.Equal(300, page1.Total);
|
||||
}
|
||||
[Fact]
|
||||
public async Task AsRouteTest()
|
||||
{
|
||||
var countAsync3 = await _virtualDbContext.Set<LogMonthLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogMonthLong>("202104");
|
||||
}).CountAsync();
|
||||
Assert.Equal(30, countAsync3);
|
||||
var countAsync2 = await _virtualDbContext.Set<LogYearLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogYearLong>("2021");
|
||||
}).CountAsync();
|
||||
Assert.Equal(300, countAsync2);
|
||||
|
||||
var countAsync4 = await _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogWeekTimeLong>("20210419_25");
|
||||
}).CountAsync();
|
||||
Assert.Equal(7, countAsync4);
|
||||
|
||||
var countAsync5 = await _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintTail<LogWeekTimeLong>("20210419_25", "20210426_02");
|
||||
}).CountAsync();
|
||||
Assert.Equal(14, countAsync5);
|
||||
|
||||
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var sum = await _virtualDbContext.Set<Order>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintDataSource<Order>("C");
|
||||
})
|
||||
.Where(o => o.CreateTime == fiveBegin).Select(o => o.Money).SumAsync();
|
||||
Assert.Equal(0, sum);
|
||||
}
|
||||
// [Fact]
|
||||
// public async Task Group_API_Test()
|
||||
// {
|
||||
|
|
|
@ -16,6 +16,7 @@ using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
|||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Extensions.ShardingPageExtensions;
|
||||
using ShardingCore.Extensions.ShardingQueryableExtensions;
|
||||
using ShardingCore.Helpers;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
|
@ -1419,6 +1420,41 @@ namespace ShardingCore.Test2x
|
|||
Assert.Equal(10, page1.Data.Count);
|
||||
Assert.Equal(300, page1.Total);
|
||||
}
|
||||
[Fact]
|
||||
public void AsRouteTest()
|
||||
{
|
||||
var countAsync3 = _virtualDbContext.Set<LogMonthLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogMonthLong>("202104");
|
||||
}).Count();
|
||||
Assert.Equal(30, countAsync3);
|
||||
var countAsync2 = _virtualDbContext.Set<LogYearLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogYearLong>("2021");
|
||||
}).Count();
|
||||
Assert.Equal(300, countAsync2);
|
||||
|
||||
var countAsync4 = _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogWeekTimeLong>("20210419_25");
|
||||
}).Count();
|
||||
Assert.Equal(7, countAsync4);
|
||||
|
||||
var countAsync5 = _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintTail<LogWeekTimeLong>("20210419_25", "20210426_02");
|
||||
}).Count();
|
||||
Assert.Equal(14, countAsync5);
|
||||
|
||||
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var sum = _virtualDbContext.Set<Order>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintDataSource<Order>("C");
|
||||
})
|
||||
.Where(o => o.CreateTime == fiveBegin).Select(o => o.Money).Sum();
|
||||
Assert.Equal(0, sum);
|
||||
}
|
||||
// [Fact]
|
||||
// public void Group_API_Test()
|
||||
// {
|
||||
|
|
|
@ -18,6 +18,7 @@ using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
|||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Extensions.ShardingPageExtensions;
|
||||
using ShardingCore.Extensions.ShardingQueryableExtensions;
|
||||
using ShardingCore.Helpers;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
|
@ -1495,6 +1496,41 @@ namespace ShardingCore.Test3x
|
|||
Assert.Equal(10, page1.Data.Count);
|
||||
Assert.Equal(300, page1.Total);
|
||||
}
|
||||
[Fact]
|
||||
public async Task AsRouteTest()
|
||||
{
|
||||
var countAsync3 = await _virtualDbContext.Set<LogMonthLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogMonthLong>("202104");
|
||||
}).CountAsync();
|
||||
Assert.Equal(30, countAsync3);
|
||||
var countAsync2 = await _virtualDbContext.Set<LogYearLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogYearLong>("2021");
|
||||
}).CountAsync();
|
||||
Assert.Equal(300, countAsync2);
|
||||
|
||||
var countAsync4 = await _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogWeekTimeLong>("20210419_25");
|
||||
}).CountAsync();
|
||||
Assert.Equal(7, countAsync4);
|
||||
|
||||
var countAsync5 = await _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintTail<LogWeekTimeLong>("20210419_25", "20210426_02");
|
||||
}).CountAsync();
|
||||
Assert.Equal(14, countAsync5);
|
||||
|
||||
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var sum = await _virtualDbContext.Set<Order>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintDataSource<Order>("C");
|
||||
})
|
||||
.Where(o => o.CreateTime == fiveBegin).Select(o => o.Money).SumAsync();
|
||||
Assert.Equal(0, sum);
|
||||
}
|
||||
// [Fact]
|
||||
// public async Task Group_API_Test()
|
||||
// {
|
||||
|
|
|
@ -17,6 +17,7 @@ using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
|||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Extensions.ShardingPageExtensions;
|
||||
using ShardingCore.Extensions.ShardingQueryableExtensions;
|
||||
using ShardingCore.Helpers;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
|
@ -1421,6 +1422,41 @@ namespace ShardingCore.Test3x
|
|||
Assert.Equal(10, page1.Data.Count);
|
||||
Assert.Equal(300, page1.Total);
|
||||
}
|
||||
[Fact]
|
||||
public void AsRouteTest()
|
||||
{
|
||||
var countAsync3 = _virtualDbContext.Set<LogMonthLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogMonthLong>("202104");
|
||||
}).Count();
|
||||
Assert.Equal(30, countAsync3);
|
||||
var countAsync2 = _virtualDbContext.Set<LogYearLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogYearLong>("2021");
|
||||
}).Count();
|
||||
Assert.Equal(300, countAsync2);
|
||||
|
||||
var countAsync4 = _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogWeekTimeLong>("20210419_25");
|
||||
}).Count();
|
||||
Assert.Equal(7, countAsync4);
|
||||
|
||||
var countAsync5 = _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintTail<LogWeekTimeLong>("20210419_25", "20210426_02");
|
||||
}).Count();
|
||||
Assert.Equal(14, countAsync5);
|
||||
|
||||
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var sum = _virtualDbContext.Set<Order>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintDataSource<Order>("C");
|
||||
})
|
||||
.Where(o => o.CreateTime == fiveBegin).Select(o => o.Money).Sum();
|
||||
Assert.Equal(0, sum);
|
||||
}
|
||||
// [Fact]
|
||||
// public void Group_API_Test()
|
||||
// {
|
||||
|
|
|
@ -18,6 +18,7 @@ using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
|||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Extensions.ShardingPageExtensions;
|
||||
using ShardingCore.Extensions.ShardingQueryableExtensions;
|
||||
using ShardingCore.Helpers;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
|
@ -1495,6 +1496,41 @@ namespace ShardingCore.Test5x
|
|||
Assert.Equal(10, page1.Data.Count);
|
||||
Assert.Equal(300, page1.Total);
|
||||
}
|
||||
[Fact]
|
||||
public async Task AsRouteTest()
|
||||
{
|
||||
var countAsync3 = await _virtualDbContext.Set<LogMonthLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogMonthLong>("202104");
|
||||
}).CountAsync();
|
||||
Assert.Equal(30, countAsync3);
|
||||
var countAsync2 = await _virtualDbContext.Set<LogYearLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogYearLong>("2021");
|
||||
}).CountAsync();
|
||||
Assert.Equal(300, countAsync2);
|
||||
|
||||
var countAsync4 = await _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogWeekTimeLong>("20210419_25");
|
||||
}).CountAsync();
|
||||
Assert.Equal(7, countAsync4);
|
||||
|
||||
var countAsync5 = await _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintTail<LogWeekTimeLong>("20210419_25", "20210426_02");
|
||||
}).CountAsync();
|
||||
Assert.Equal(14, countAsync5);
|
||||
|
||||
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var sum = await _virtualDbContext.Set<Order>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintDataSource<Order>("C");
|
||||
})
|
||||
.Where(o => o.CreateTime == fiveBegin).Select(o => o.Money).SumAsync();
|
||||
Assert.Equal(0, sum);
|
||||
}
|
||||
// [Fact]
|
||||
// public async Task Group_API_Test()
|
||||
// {
|
||||
|
|
|
@ -17,6 +17,7 @@ using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
|||
using ShardingCore.Exceptions;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.Extensions.ShardingPageExtensions;
|
||||
using ShardingCore.Extensions.ShardingQueryableExtensions;
|
||||
using ShardingCore.Helpers;
|
||||
using ShardingCore.Sharding;
|
||||
using ShardingCore.Sharding.ParallelTables;
|
||||
|
@ -1421,6 +1422,41 @@ namespace ShardingCore.Test5x
|
|||
Assert.Equal(10, page1.Data.Count);
|
||||
Assert.Equal(300, page1.Total);
|
||||
}
|
||||
[Fact]
|
||||
public void AsRouteTest()
|
||||
{
|
||||
var countAsync3 = _virtualDbContext.Set<LogMonthLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogMonthLong>("202104");
|
||||
}).Count();
|
||||
Assert.Equal(30, countAsync3);
|
||||
var countAsync2 = _virtualDbContext.Set<LogYearLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogYearLong>("2021");
|
||||
}).Count();
|
||||
Assert.Equal(300, countAsync2);
|
||||
|
||||
var countAsync4 = _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddMustTail<LogWeekTimeLong>("20210419_25");
|
||||
}).Count();
|
||||
Assert.Equal(7, countAsync4);
|
||||
|
||||
var countAsync5 = _virtualDbContext.Set<LogWeekTimeLong>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintTail<LogWeekTimeLong>("20210419_25", "20210426_02");
|
||||
}).Count();
|
||||
Assert.Equal(14, countAsync5);
|
||||
|
||||
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var sum = _virtualDbContext.Set<Order>().AsRoute(o =>
|
||||
{
|
||||
o.TryCreateOrAddHintDataSource<Order>("C");
|
||||
})
|
||||
.Where(o => o.CreateTime == fiveBegin).Select(o => o.Money).Sum();
|
||||
Assert.Equal(0, sum);
|
||||
}
|
||||
// [Fact]
|
||||
// public void Group_API_Test()
|
||||
// {
|
||||
|
|
Loading…
Reference in New Issue