修复efcore6下相同tail不自动建表
This commit is contained in:
parent
f65e2a7ae3
commit
1950a5c0ec
|
@ -1,9 +1,9 @@
|
|||
:start
|
||||
::定义版本
|
||||
set EFCORE2=2.3.1.41
|
||||
set EFCORE3=3.3.1.41
|
||||
set EFCORE5=5.3.1.41
|
||||
set EFCORE6=6.3.1.41
|
||||
set EFCORE2=2.3.1.42
|
||||
set EFCORE3=3.3.1.42
|
||||
set EFCORE5=5.3.1.42
|
||||
set EFCORE6=6.3.1.42
|
||||
|
||||
::删除所有bin与obj下的文件
|
||||
@echo off
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace ShardingCore.Extensions
|
|||
var modelSourceDependencies =
|
||||
dependenciesModelSource.GetPropertyValue("Dependencies") as ModelSourceDependencies;
|
||||
IMemoryCache memoryCache = modelSourceDependencies.MemoryCache;
|
||||
object key1 = modelSourceDependencies.ModelCacheKeyFactory.Create(dbContext);
|
||||
object key1 = modelSourceDependencies.ModelCacheKeyFactory.Create(dbContext,true);
|
||||
memoryCache.Remove(key1);
|
||||
#endif
|
||||
#if EFCORE5
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes;
|
||||
|
||||
namespace ShardingCore
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/3/3 16:15:11
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public class ShardingDbConfigOptions
|
||||
{
|
||||
|
||||
|
||||
private readonly Dictionary<Type,Type> _virtualRoutes = new Dictionary<Type, Type>();
|
||||
public void AddShardingTableRoute<TRoute>() where TRoute : IVirtualTableRoute
|
||||
{
|
||||
var routeType = typeof(TRoute);
|
||||
//获取类型
|
||||
var genericVirtualRoute = routeType.GetInterfaces().FirstOrDefault(it => it.IsInterface && it.IsGenericType && it.GetGenericTypeDefinition() == typeof(IVirtualTableRoute<>)
|
||||
&& it.GetGenericArguments().Any());
|
||||
if (genericVirtualRoute == null)
|
||||
throw new ArgumentException("add sharding route type error not assignable from IVirtualTableRoute<>.");
|
||||
|
||||
var shardingEntityType = genericVirtualRoute.GetGenericArguments()[0];
|
||||
if (shardingEntityType == null)
|
||||
throw new ArgumentException("add sharding table route type error not assignable from IVirtualTableRoute<>");
|
||||
if (!_virtualRoutes.ContainsKey(shardingEntityType))
|
||||
{
|
||||
_virtualRoutes.Add(shardingEntityType, routeType);
|
||||
}
|
||||
}
|
||||
|
||||
public Type GetVirtualRoute(Type entityType)
|
||||
{
|
||||
if (!_virtualRoutes.ContainsKey(entityType))
|
||||
throw new ArgumentException("not found IVirtualTableRoute");
|
||||
return _virtualRoutes[entityType];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,14 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ShardingCore.Core;
|
||||
|
||||
namespace ShardingCore.Test6x.Domain.Entities
|
||||
{
|
||||
public class Order
|
||||
public class Order:IShardingDataSource,IShardingTable
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[ShardingDataSourceKey]
|
||||
public string Area { get; set; }
|
||||
public long Money { get; set; }
|
||||
[ShardingTableKey]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -486,14 +486,14 @@ namespace ShardingCore.Test6x
|
|||
public async Task OrderCountTest()
|
||||
{
|
||||
var asyncCount = await _virtualDbContext.Set<Order>().CountAsync();
|
||||
Assert.Equal(360, asyncCount);
|
||||
Assert.Equal(320, asyncCount);
|
||||
var syncCount = _virtualDbContext.Set<Order>().Count();
|
||||
Assert.Equal(360, syncCount);
|
||||
Assert.Equal(320, syncCount);
|
||||
|
||||
var countA =await _virtualDbContext.Set<Order>().CountAsync(o=>o.Area=="A");
|
||||
var countB =await _virtualDbContext.Set<Order>().CountAsync(o=>o.Area=="B");
|
||||
var countC =await _virtualDbContext.Set<Order>().CountAsync(o=>o.Area=="C");
|
||||
Assert.Equal(360, countA+ countB+ countC);
|
||||
Assert.Equal(320, countA+ countB+ countC);
|
||||
var fourBegin = new DateTime(2021, 4, 1).Date;
|
||||
var fiveBegin = new DateTime(2021, 5, 1).Date;
|
||||
var fourCount = await _virtualDbContext.Set<Order>().Where(o=>o.CreateTime>=fourBegin&&o.CreateTime<fiveBegin).CountAsync();
|
||||
|
@ -512,7 +512,7 @@ namespace ShardingCore.Test6x
|
|||
public async Task OrderOrderTest()
|
||||
{
|
||||
var orders = await _virtualDbContext.Set<Order>().OrderBy(o => o.CreateTime).ToListAsync();
|
||||
Assert.Equal(360,orders.Count);
|
||||
Assert.Equal(320,orders.Count);
|
||||
var i = 0;
|
||||
foreach (var order in orders)
|
||||
{
|
||||
|
@ -523,9 +523,9 @@ namespace ShardingCore.Test6x
|
|||
var threeMonth = new DateTime(2021, 3, 1);
|
||||
var orderPage = await _virtualDbContext.Set<Order>().Where(o=>o.CreateTime > threeMonth).OrderByDescending(o => o.CreateTime).ToShardingPageAsync(1,20);
|
||||
Assert.Equal(20, orderPage.Data.Count);
|
||||
Assert.Equal(300,orderPage.Total);
|
||||
Assert.Equal(260,orderPage.Total);
|
||||
|
||||
var j = 359;
|
||||
var j = 319;
|
||||
foreach (var order in orderPage.Data)
|
||||
{
|
||||
Assert.Equal(j, order.Money);
|
||||
|
|
|
@ -53,10 +53,5 @@ namespace ShardingCore.Test6x.Shardings
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Configure(EntityMetadataDataSourceBuilder<Order> builder)
|
||||
{
|
||||
builder.ShardingProperty(o => o.Area);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ namespace ShardingCore.Test6x
|
|||
var areas = new List<string>(){"A","B","C"};
|
||||
List<Order> orders = new List<Order>(360);
|
||||
var begin = new DateTime(2021, 1, 1);
|
||||
for (int i = 0; i < 360; i++)
|
||||
for (int i = 0; i < 320; i++)
|
||||
{
|
||||
orders.Add(new Order()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue