From 32bb3b8ddcb604d55d12497ffd39478213391d9a Mon Sep 17 00:00:00 2001 From: xuejmnet <326308290@qq.com> Date: Fri, 27 Aug 2021 21:47:53 +0800 Subject: [PATCH 1/4] 1 --- samples/Sample.SqlServer/DbContexts/DefaultShardingDbContext.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/Sample.SqlServer/DbContexts/DefaultShardingDbContext.cs b/samples/Sample.SqlServer/DbContexts/DefaultShardingDbContext.cs index 35540c8a..be0a006f 100644 --- a/samples/Sample.SqlServer/DbContexts/DefaultShardingDbContext.cs +++ b/samples/Sample.SqlServer/DbContexts/DefaultShardingDbContext.cs @@ -17,6 +17,7 @@ namespace Sample.SqlServer.DbContexts protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); + //配置默认和DefaultTableDbContext一样 modelBuilder.ApplyConfiguration(new SysUserModMap()); modelBuilder.ApplyConfiguration(new SysTestMap()); } From 9698230a7d0bd8a3657be2318ebb9deac44bf3f6 Mon Sep 17 00:00:00 2001 From: xuejmnet <326308290@qq.com> Date: Sat, 28 Aug 2021 12:30:17 +0800 Subject: [PATCH 2/4] 1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 76e259c9..9e8b8d17 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ or op.CreateShardingTableOnStart = true; op.UseShardingOptionsBuilder( (connection, builder) => builder.UseSqlServer(connection).UseLoggerFactory(efLogger), - builder => builder.UseSqlServer("Data Source=localhost;Initial Catalog=ShardingCoreDBxx2;Integrated Security=True;").UseLoggerFactory(efLogger)); + (conStr,builder) => builder.UseSqlServer(conStr).UseLoggerFactory(efLogger));//conStr不一定需要使用委托参数可以自定义来实现读写分离 op.AddShardingTableRoute(); }); } From 008aab92d48dd71f742b2f0168f58f58875ffbf5 Mon Sep 17 00:00:00 2001 From: xuejmnet <326308290@qq.com> Date: Sat, 28 Aug 2021 14:42:26 +0800 Subject: [PATCH 3/4] 1 --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 9e8b8d17..ecd0d5eb 100644 --- a/README.md +++ b/README.md @@ -325,14 +325,9 @@ ctor inject IShardingRouteManager shardingRouteManager [参考](https://github.com/xuejmnet/sharding-core/tree/main/samples/Samples.AutoByDate.SqlServer) ## 事务 -默认savechanges支持事务如果需要where.update需要手动开启事务 +默认savechanges支持事务 ```c# -1. await _defaultShardingDbContext.SaveChangesAsync(); - 2. - var tran=_defaultShardingDbContext.BeginTransaction(); - await _defaultShardingDbContext.SaveChangesAsync(); - tran.commit() ``` ## 读写分离 From 8a6a05fa24ba4f8dde5c042777fbd1ad163566e4 Mon Sep 17 00:00:00 2001 From: xuejmnet <326308290@qq.com> Date: Sun, 29 Aug 2021 11:12:57 +0800 Subject: [PATCH 4/4] 1 --- README.md | 1 + .../Shardings/SysUserLogByDayVirtualTableRoute.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index ecd0d5eb..89dc654a 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,7 @@ AbstractSimpleShardingYearKeyDateTimeVirtualTableRoute |按时间 |yyyy | `>,>=, AbstractSimpleShardingYearKeyLongVirtualTableRoute |按时间戳 |yyyy | `>,>=,<,<=,=,contains` 注:`contains`表示为`o=>ids.contains(o.shardingkey)` +注:使用默认的按时间分表的路由规则会让你重写一个GetBeginTime的方法这个方法必须使用静态值如:new DateTime(2021,1,1)不可以用动态值比如DateTime.Now因为每次重新启动都会调用该方法动态情况下会导致每次都不一致 #高级 diff --git a/samples/Samples.AutoByDate.SqlServer/Shardings/SysUserLogByDayVirtualTableRoute.cs b/samples/Samples.AutoByDate.SqlServer/Shardings/SysUserLogByDayVirtualTableRoute.cs index 8e5d77f1..4b394a40 100644 --- a/samples/Samples.AutoByDate.SqlServer/Shardings/SysUserLogByDayVirtualTableRoute.cs +++ b/samples/Samples.AutoByDate.SqlServer/Shardings/SysUserLogByDayVirtualTableRoute.cs @@ -15,6 +15,8 @@ namespace Samples.AutoByDate.SqlServer.Shardings { public override DateTime GetBeginTime() { + //必须返回固定值比如new DateTime(2021,1,1) + //如果返回动态值会导致程序重新启动这个值就会变动导致无法获取之前的表 return DateTime.Now.AddDays(-2); } }