修复仅分库对象
This commit is contained in:
parent
d5f3aa7fc7
commit
531f2e9596
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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) =>
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -6,11 +6,21 @@ using Sample.SqlServerShardingDataSource.Entities;
|
|||
using ShardingCore.Core.EntityMetadatas;
|
||||
using ShardingCore.Core.VirtualRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions;
|
||||
using ShardingCore.Helpers;
|
||||
|
||||
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>()
|
||||
{
|
||||
"A", "B", "C"
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue