Merge branch 'main' of github.com:dotnetcore/sharding-core

This commit is contained in:
xuejiaming 2022-08-17 11:08:35 +08:00
commit 94b99ffce9
5 changed files with 16 additions and 2 deletions

View File

@ -13,6 +13,7 @@ namespace Sample.MySql
{
public static void Main(string[] args)
{
var list = Enumerable.Range(1,3).Select(o=>(o%100).ToString().PadLeft(2,'0')).ToList();
CreateHostBuilder(args).Build().Run();
}

View File

@ -67,7 +67,7 @@ namespace Sample.MySql
// });
services.AddMultiShardingDbContext<OtherDbContext>()
.UseRouteConfig(op => { op.AddShardingTableRoute<MyUserRoute>(); })
.UseConfig(o =>
.UseConfig((sp,o) =>
{
o.ThrowIfQueryRouteNotMatch = false;
o.UseShardingQuery((conStr, builder) =>

View File

@ -9,7 +9,7 @@ namespace Sample.SqlServer.Domain.Maps
public void Configure(EntityTypeBuilder<SysTest> builder)
{
builder.HasKey(o => o.Id);
builder.Property(o => o.Id).IsRequired().HasMaxLength(128);
builder.Property(o => o.Id).ValueGeneratedOnAdd().IsRequired().HasMaxLength(128);
builder.Property(o => o.UserId).IsRequired().HasMaxLength(128);
builder.ToTable(nameof(SysTest));
}

View File

@ -12,6 +12,15 @@ namespace Sample.SqlServerShardingDataSource.VirtualRoutes
{
public class SysUserVirtualDataSourceRoute : AbstractShardingOperatorVirtualDataSourceRoute<SysUser, string>
{
// private readonly List<string> _dataSources = new List<string>()
// {
// "00", "01", "02","03"
// };
// //我们设置区域就是数据库
// public override string ShardingKeyToDataSourceName(object shardingKey)
// {
// return Math.Abs(ShardingCoreHelper.GetStringHashCode(shardingKey?.ToString() ?? string.Empty)%4).ToString().PadLeft(2,'0');
// }
private readonly List<string> _dataSources = new List<string>()
{
"00", "01", "02","03"

View File

@ -107,6 +107,10 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine
}
}
}
else
{
routeMaps.Add(dataSourceName,new Dictionary<Type, ISet<TableRouteUnit>>());
}
}
return new ShardingRouteResult(sqlRouteUnits, sqlRouteUnits.Count == 0, dataSourceCount > 1, isCrossTable,