diff --git a/README.md b/README.md index 15f505de..9c9cbda1 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,7 @@ context.Where(shardingBatchUpdateEntry.Where).Update(shardingBatchUpdateEntry.Up 使用时需要注意 - 实体对象是否继承`IShardingEntity` - 实体对象是否有`ShardingKey` +- 实体对象是否映射配置已实现`IEntityTypeConfiguration` - 实体对象是否已经实现了一个虚拟路由 - startup是否已经添加虚拟路由 @@ -326,7 +327,7 @@ context.Where(shardingBatchUpdateEntry.Where).Update(shardingBatchUpdateEntry.Up - [支持更多数据库查询] # 最后 -该框架借鉴了大部分分表组件的思路,目前提供的接口都已经实现,并且支持跨表查询,基于分页查询该框架也使用了流式查询保证不会再skip大数据的时候内存会爆炸,至于groupby目前已经在开发支持了,相信不久后就会发布新版本,目前这个库只是一个刚刚成型的库还有很多不完善的地方希望大家多多包涵,如果喜欢的话也希望大家给个star. +该框架借鉴了大部分分表组件的思路,目前提供的接口都已经实现,并且支持跨表查询,基于分页查询该框架也使用了流式查询保证不会再skip大数据的时候内存会爆炸,目前这个库只是一个刚刚成型的库还有很多不完善的地方希望大家多多包涵,如果喜欢的话也希望大家给个star. 该文档是我晚上赶工赶出来的也想趁热打铁希望更多的人关注,也希望更多的人可以交流。 凭借各大开源生态圈提供的优秀代码和思路才有的这个框架,希望可以为.Net生态提供一份微薄之力,该框架本人会一直长期维护,有大神技术支持可以联系下方方式欢迎star :) diff --git a/samples/Sample.SqlServer/Shardings/SysUserModVirtualRoute.cs b/samples/Sample.SqlServer/Shardings/SysUserModVirtualRoute.cs index 615c7319..a1a2d6a7 100644 --- a/samples/Sample.SqlServer/Shardings/SysUserModVirtualRoute.cs +++ b/samples/Sample.SqlServer/Shardings/SysUserModVirtualRoute.cs @@ -16,7 +16,7 @@ namespace Sample.SqlServer.Shardings */ public class SysUserModVirtualRoute : AbstractSimpleShardingModKeyStringVirtualRoute { - public SysUserModVirtualRoute() : base(3) + public SysUserModVirtualRoute() : base(2,3) { } } diff --git a/src/ShardingCore/VirtualRoutes/Mods/AbstractSimpleShardingModKeyIntVirtualRoute.cs b/src/ShardingCore/VirtualRoutes/Mods/AbstractSimpleShardingModKeyIntVirtualRoute.cs index caed449a..cf730b13 100644 --- a/src/ShardingCore/VirtualRoutes/Mods/AbstractSimpleShardingModKeyIntVirtualRoute.cs +++ b/src/ShardingCore/VirtualRoutes/Mods/AbstractSimpleShardingModKeyIntVirtualRoute.cs @@ -21,11 +21,19 @@ namespace ShardingCore.VirtualRoutes.Mods public abstract class AbstractSimpleShardingModKeyIntVirtualRoute:AbstractShardingOperatorVirtualRoute where T:class,IShardingEntity { protected readonly int Mod; - protected AbstractSimpleShardingModKeyIntVirtualRoute(int mod) + protected readonly int TailLength; + protected readonly char PaddingChar; + protected AbstractSimpleShardingModKeyIntVirtualRoute(int tailLength,int mod,char paddingChar='0') { + if(tailLength<1) + throw new ArgumentException($"{nameof(tailLength)} less than 1 "); if (mod < 1) throw new ArgumentException($"{nameof(mod)} less than 1 "); + if (string.IsNullOrWhiteSpace(paddingChar.ToString())) + throw new ArgumentException($"{nameof(paddingChar)} cant empty "); + TailLength = tailLength; Mod = mod; + PaddingChar = paddingChar; } protected override int ConvertToShardingKey(object shardingKey) { @@ -35,7 +43,7 @@ namespace ShardingCore.VirtualRoutes.Mods public override string ShardingKeyToTail(object shardingKey) { var shardingKeyInt = ConvertToShardingKey(shardingKey); - return Math.Abs(shardingKeyInt % Mod).ToString(); + return Math.Abs(shardingKeyInt % Mod).ToString().PadLeft(TailLength,PaddingChar); } public override List GetAllTails() diff --git a/src/ShardingCore/VirtualRoutes/Mods/AbstractSimpleShardingModKeyStringVirtualRoute.cs b/src/ShardingCore/VirtualRoutes/Mods/AbstractSimpleShardingModKeyStringVirtualRoute.cs index f0e01a93..60f71e19 100644 --- a/src/ShardingCore/VirtualRoutes/Mods/AbstractSimpleShardingModKeyStringVirtualRoute.cs +++ b/src/ShardingCore/VirtualRoutes/Mods/AbstractSimpleShardingModKeyStringVirtualRoute.cs @@ -22,9 +22,19 @@ namespace ShardingCore.VirtualRoutes.Mods public abstract class AbstractSimpleShardingModKeyStringVirtualRoute:AbstractShardingOperatorVirtualRoute where T:class,IShardingEntity { protected readonly int Mod; - protected AbstractSimpleShardingModKeyStringVirtualRoute(int mod) + protected readonly int TailLength; + protected readonly char PaddingChar; + protected AbstractSimpleShardingModKeyStringVirtualRoute(int tailLength,int mod,char paddingChar='0') { + if(tailLength<1) + throw new ArgumentException($"{nameof(tailLength)} less than 1 "); + if (mod < 1) + throw new ArgumentException($"{nameof(mod)} less than 1 "); + if (string.IsNullOrWhiteSpace(paddingChar.ToString())) + throw new ArgumentException($"{nameof(paddingChar)} cant empty "); + TailLength = tailLength; Mod = mod; + PaddingChar = paddingChar; } /// /// 如何将shardingkey转成对应的tail @@ -34,7 +44,7 @@ namespace ShardingCore.VirtualRoutes.Mods public override string ShardingKeyToTail(object shardingKey) { var shardingKeyStr = ConvertToShardingKey(shardingKey); - return Math.Abs(ShardingCoreHelper.GetStringHashCode(shardingKeyStr) % Mod).ToString(); + return Math.Abs(ShardingCoreHelper.GetStringHashCode(shardingKeyStr) % Mod).ToString().PadLeft(TailLength,PaddingChar);; } protected override string ConvertToShardingKey(object shardingKey) { diff --git a/test/ShardingCore.Test50.MySql/Shardings/SysUserModVirtualRoute.cs b/test/ShardingCore.Test50.MySql/Shardings/SysUserModVirtualRoute.cs index c0ebbd40..6dac9b37 100644 --- a/test/ShardingCore.Test50.MySql/Shardings/SysUserModVirtualRoute.cs +++ b/test/ShardingCore.Test50.MySql/Shardings/SysUserModVirtualRoute.cs @@ -16,7 +16,7 @@ namespace ShardingCore.Test50.MySql.Shardings */ public class SysUserModVirtualRoute : AbstractSimpleShardingModKeyStringVirtualRoute { - public SysUserModVirtualRoute() : base(3) + public SysUserModVirtualRoute() : base(2,3) { } diff --git a/test/ShardingCore.Test50/Shardings/SysUserModVirtualRoute.cs b/test/ShardingCore.Test50/Shardings/SysUserModVirtualRoute.cs index 2b67cbfe..65926d44 100644 --- a/test/ShardingCore.Test50/Shardings/SysUserModVirtualRoute.cs +++ b/test/ShardingCore.Test50/Shardings/SysUserModVirtualRoute.cs @@ -16,7 +16,7 @@ namespace ShardingCore.Test50.Shardings */ public class SysUserModVirtualRoute : AbstractSimpleShardingModKeyStringVirtualRoute { - public SysUserModVirtualRoute() : base(3) + public SysUserModVirtualRoute() : base(2,3) { }