优化订单创建分表的方式
This commit is contained in:
parent
a0a223151d
commit
519fe66a06
|
@ -30,13 +30,13 @@ namespace Sample.SqlServer
|
|||
o => o.UseSqlServer("Data Source=localhost;Initial Catalog=ShardingCoreDB;Integrated Security=True;")
|
||||
, op =>
|
||||
{
|
||||
op.EnsureCreatedWithOutShardingTable = true;
|
||||
op.CreateShardingTableOnStart = true;
|
||||
op.EnsureCreatedWithOutShardingTable = false;
|
||||
op.CreateShardingTableOnStart = false;
|
||||
op.UseShardingOptionsBuilder(
|
||||
(connection, builder) => builder.UseSqlServer(connection).UseLoggerFactory(efLogger),//使用dbconnection创建dbcontext支持事务
|
||||
(conStr,builder) => builder.UseSqlServer(conStr).UseLoggerFactory(efLogger
|
||||
(conStr,builder) => builder.UseSqlServer(conStr).UseLoggerFactory(efLogger)
|
||||
//.ReplaceService<IQueryTranslationPostprocessorFactory,SqlServer2008QueryTranslationPostprocessorFactory>()//支持sqlserver2008r2
|
||||
));//使用链接字符串创建dbcontext
|
||||
);//使用链接字符串创建dbcontext
|
||||
op.AddShardingTableRoute<SysUserModVirtualTableRoute>();
|
||||
});
|
||||
////不支持MARS不支持追踪的
|
||||
|
|
|
@ -26,11 +26,11 @@ namespace Samples.AutoByDate.SqlServer.Jobs
|
|||
|
||||
public void AutoCreateTable(IVirtualTableManager virtualTableManager, IShardingTableCreator tableCreator)
|
||||
{
|
||||
var allVirtualTables = virtualTableManager.GetAllVirtualTables<DefaultShardingDbContext>();
|
||||
foreach (var virtualTable in allVirtualTables)
|
||||
{
|
||||
if (virtualTable.EntityType == typeof(SysUserLogByDay))
|
||||
var virtualTable = virtualTableManager.GetVirtualTable<DefaultShardingDbContext, SysUserLogByDay>();
|
||||
if (virtualTable == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var now = DateTime.Now.Date.AddDays(1);
|
||||
var tail = virtualTable.GetVirtualRoute().ShardingKeyToTail(now);
|
||||
try
|
||||
|
@ -45,5 +45,3 @@ namespace Samples.AutoByDate.SqlServer.Jobs
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue