添加shardingcore吧版本使用说明
This commit is contained in:
parent
26b1916e09
commit
c9aaa32eb3
|
@ -50,6 +50,10 @@ Release | EF Core | .NET (Core)
|
||||||
[6.7.0.0+](https://www.nuget.org/packages/ShardingCore)| 2.x | netcoreapp2
|
[6.7.0.0+](https://www.nuget.org/packages/ShardingCore)| 2.x | netcoreapp2
|
||||||
|
|
||||||
|
|
||||||
|
## 如何选择版本
|
||||||
|
- 如果你的efcore版本小于等于6,那么就是使用shardingcore 6.x.x.x的最新版本
|
||||||
|
- 如果你的efcore版本等于7,那么就是使用shardingcore 7.x.x.x的最新版本
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
5步实现按月分表,且支持自动化建表建库
|
5步实现按月分表,且支持自动化建表建库
|
||||||
### 第一步安装依赖
|
### 第一步安装依赖
|
||||||
|
|
|
@ -48,6 +48,10 @@ Release | EF Core | .NET (Core)
|
||||||
[6.7.0.0+](https://www.nuget.org/packages/ShardingCore)| 3.x | netcoreapp3 or netstandard2.0
|
[6.7.0.0+](https://www.nuget.org/packages/ShardingCore)| 3.x | netcoreapp3 or netstandard2.0
|
||||||
[6.7.0.0+](https://www.nuget.org/packages/ShardingCore)| 2.x | netcoreapp2
|
[6.7.0.0+](https://www.nuget.org/packages/ShardingCore)| 2.x | netcoreapp2
|
||||||
|
|
||||||
|
## How Choose Version
|
||||||
|
- if u efcore version <=6 use shardingcore 6.x.x.x last version
|
||||||
|
- if u efcore version ==6 use shardingcore 7.x.x.x last version
|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
5 steps implement sharding by month and support auto create table by month
|
5 steps implement sharding by month and support auto create table by month
|
||||||
### Step 1: Install the package
|
### Step 1: Install the package
|
||||||
|
|
|
@ -171,20 +171,18 @@ namespace Sample.MySql.Controllers
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get2()
|
public async Task<IActionResult> Get2()
|
||||||
{
|
{
|
||||||
// var sql= from a in _defaultTableDbContext.Set<DynamicTable>()
|
var dateTime = new DateTime(2021,1,1);
|
||||||
// join b in _defaultTableDbContext.Set<SysTest>()
|
var sql= from a in _defaultTableDbContext.Set<SysUserLogByMonth>().Where(o=>o.Time==dateTime)
|
||||||
// on a.Id equals b.Id into t1
|
join b in _defaultTableDbContext.Set<SysTest>()
|
||||||
// from aa1 in t1.DefaultIfEmpty()
|
on a.Id equals b.Id into t1
|
||||||
// // join bc in _defaultTableDbContext.Set<SysTest>()
|
from aa1 in t1.DefaultIfEmpty()
|
||||||
// // on a.Id equals bc.Id into t2
|
select new
|
||||||
// // from aa2 in t2.DefaultIfEmpty()
|
{
|
||||||
// select new
|
ID = a.Id
|
||||||
// {
|
};
|
||||||
// ID = a.Id
|
var listAsync =await sql.ToListAsync();
|
||||||
// };
|
// var sysUserMods1 = await _defaultTableDbContext.Set<SysUserMod>().FromSqlRaw("select * from SysUserMod where id='2'").ToListAsync();
|
||||||
// var listAsync =await sql.ToListAsync();
|
// var sysUserMods2 = await _defaultTableDbContext.Set<SysTest>().FromSqlRaw("select * from SysTest where id='2'").ToListAsync();
|
||||||
var sysUserMods1 = await _defaultTableDbContext.Set<SysUserMod>().FromSqlRaw("select * from SysUserMod where id='2'").ToListAsync();
|
|
||||||
var sysUserMods2 = await _defaultTableDbContext.Set<SysTest>().FromSqlRaw("select * from SysTest where id='2'").ToListAsync();
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,23 +29,24 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine
|
||||||
_entityMetadataManager = entityMetadataManager;
|
_entityMetadataManager = entityMetadataManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TableRouteUnit> GetEntityRouteUnit(DataSourceRouteResult dataSourceRouteResult,Type shardingEntity,IQueryable queryable)
|
private List<TableRouteUnit> GetEntityRouteUnit(DataSourceRouteResult dataSourceRouteResult,
|
||||||
|
Type shardingEntity, IQueryable queryable)
|
||||||
{
|
{
|
||||||
// if (!_entityMetadataManager.IsShardingTable(shardingEntity))
|
// if (!_entityMetadataManager.IsShardingTable(shardingEntity))
|
||||||
// {
|
// {
|
||||||
// // var dataSourceNames = dataSourceRouteResult.IntersectDataSources;
|
// var dataSourceNames = dataSourceRouteResult.IntersectDataSources;
|
||||||
// // var tableRouteUnits = new List<TableRouteUnit>(dataSourceNames.Count);
|
// var tableRouteUnits = new List<TableRouteUnit>(dataSourceNames.Count);
|
||||||
// // foreach (var dataSourceName in dataSourceNames)
|
// foreach (var dataSourceName in dataSourceNames)
|
||||||
// // {
|
// {
|
||||||
// // var shardingRouteUnit = new TableRouteUnit(dataSourceName, string.Empty, shardingEntity);
|
// var shardingRouteUnit = new TableRouteUnit(dataSourceName, string.Empty, shardingEntity);
|
||||||
// // tableRouteUnits.Add(shardingRouteUnit);
|
// tableRouteUnits.Add(shardingRouteUnit);
|
||||||
// // }
|
// }
|
||||||
// // return tableRouteUnits;
|
// return tableRouteUnits;
|
||||||
// return new List<TableRouteUnit>(0);
|
|
||||||
// }
|
// }
|
||||||
var virtualTableRoute = _tableRouteManager.GetRoute(shardingEntity);
|
var virtualTableRoute = _tableRouteManager.GetRoute(shardingEntity);
|
||||||
return virtualTableRoute.RouteWithPredicate(dataSourceRouteResult, queryable, true);
|
return virtualTableRoute.RouteWithPredicate(dataSourceRouteResult, queryable, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingRouteResult Route(TableRouteRuleContext tableRouteRuleContext)
|
public ShardingRouteResult Route(TableRouteRuleContext tableRouteRuleContext)
|
||||||
{
|
{
|
||||||
Dictionary<string /*dataSourceName*/, Dictionary<Type /*entityType*/, ISet<TableRouteUnit>>> routeMaps =
|
Dictionary<string /*dataSourceName*/, Dictionary<Type /*entityType*/, ISet<TableRouteUnit>>> routeMaps =
|
||||||
|
@ -60,7 +61,9 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var shardingRouteUnits = GetEntityRouteUnit(tableRouteRuleContext.DataSourceRouteResult,shardingEntity, shardingEntityKv.Value ?? tableRouteRuleContext.Queryable);
|
|
||||||
|
var shardingRouteUnits = GetEntityRouteUnit(tableRouteRuleContext.DataSourceRouteResult, shardingEntity,
|
||||||
|
shardingEntityKv.Value ?? tableRouteRuleContext.Queryable);
|
||||||
|
|
||||||
foreach (var shardingRouteUnit in shardingRouteUnits)
|
foreach (var shardingRouteUnit in shardingRouteUnits)
|
||||||
{
|
{
|
||||||
|
@ -104,7 +107,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine
|
||||||
{
|
{
|
||||||
var routeMap = routeMaps[dataSourceName];
|
var routeMap = routeMaps[dataSourceName];
|
||||||
var tableRouteResults = routeMap.Select(o => o.Value).Cartesian()
|
var tableRouteResults = routeMap.Select(o => o.Value).Cartesian()
|
||||||
.Select(o => new TableRouteResult(o.ToList())).Where(o=>!o.IsEmpty).ToList();
|
.Select(o => new TableRouteResult(o.ToList())).Where(o => !o.IsEmpty).ToList();
|
||||||
if (tableRouteResults.IsNotEmpty())
|
if (tableRouteResults.IsNotEmpty())
|
||||||
{
|
{
|
||||||
dataSourceCount++;
|
dataSourceCount++;
|
||||||
|
@ -112,6 +115,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine
|
||||||
{
|
{
|
||||||
isCrossTable = true;
|
isCrossTable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var tableRouteResult in tableRouteResults)
|
foreach (var tableRouteResult in tableRouteResults)
|
||||||
{
|
{
|
||||||
if (tableRouteResult.ReplaceTables.Count > 1)
|
if (tableRouteResult.ReplaceTables.Count > 1)
|
||||||
|
@ -122,6 +126,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine
|
||||||
existCrossTableTails = true;
|
existCrossTableTails = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlRouteUnits.Add(new SqlRouteUnit(dataSourceName, tableRouteResult));
|
sqlRouteUnits.Add(new SqlRouteUnit(dataSourceName, tableRouteResult));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +147,5 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.RoutingRuleEngine
|
||||||
// return sqlRouteUnits;
|
// return sqlRouteUnits;
|
||||||
// return routeMaps.Select(o => o.Value).Cartesian().Where(o=>o).Select(o => new TableRouteResult(o,_shardingDatabaseProvider.GetShardingDbContextType()));
|
// return routeMaps.Select(o => o.Value).Cartesian().Where(o=>o).Select(o => new TableRouteResult(o,_shardingDatabaseProvider.GetShardingDbContextType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue