发布preview3版本

This commit is contained in:
xuejiaming 2021-12-25 12:43:57 +08:00
parent 6da62de08a
commit bc9748f389
15 changed files with 65 additions and 18 deletions

View File

@ -1,9 +1,9 @@
:start :start
::定义版本 ::定义版本
set EFCORE2=2.3.2.00-preview1 set EFCORE2=2.3.2.00-preview3
set EFCORE3=3.3.2.00-preview1 set EFCORE3=3.3.2.00-preview3
set EFCORE5=5.3.2.00-preview1 set EFCORE5=5.3.2.00-preview3
set EFCORE6=6.3.2.00-preview1 set EFCORE6=6.3.2.00-preview3
::删除所有bin与obj下的文件 ::删除所有bin与obj下的文件
@echo off @echo off

View File

@ -34,7 +34,7 @@ namespace Sample.SqlServerShardingAll.VirtualDataSourceRoutes
return true; return true;
} }
public override Expression<Func<string, bool>> GetMainRouteFilter(string shardingKey, ShardingOperatorEnum shardingOperator) public override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{ {
var t = ShardingKeyToDataSourceName(shardingKey); var t = ShardingKeyToDataSourceName(shardingKey);

View File

@ -34,7 +34,7 @@ namespace Sample.SqlServerShardingAll.VirtualDataSourceRoutes
return true; return true;
} }
public override Expression<Func<string, bool>> GetMainRouteFilter(string shardingKey, ShardingOperatorEnum shardingOperator) public override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{ {
var t = ShardingKeyToDataSourceName(shardingKey); var t = ShardingKeyToDataSourceName(shardingKey);

View File

@ -34,7 +34,7 @@ namespace Sample.SqlServerShardingDataSource.VirtualRoutes
return true; return true;
} }
public override Expression<Func<string, bool>> GetMainRouteFilter(string shardingKey, ShardingOperatorEnum shardingOperator) public override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{ {
var t = ShardingKeyToDataSourceName(shardingKey); var t = ShardingKeyToDataSourceName(shardingKey);

View File

@ -34,7 +34,7 @@ namespace Sample.SqlServerShardingDataSource.VirtualRoutes
return true; return true;
} }
public override Expression<Func<string, bool>> GetMainRouteFilter(string shardingKey, ShardingOperatorEnum shardingOperator) public override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{ {
var t = ShardingKeyToDataSourceName(shardingKey); var t = ShardingKeyToDataSourceName(shardingKey);

View File

@ -29,7 +29,7 @@ namespace Sample.SqlServerShardingTable.VirtualRoutes
private Expression<Func<string, bool>> GetIdRouteFilter(object shardingKey, private Expression<Func<string, bool>> GetIdRouteFilter(object shardingKey,
ShardingOperatorEnum shardingOperator) ShardingOperatorEnum shardingOperator)
{ {
//解析雪花id 需要考虑异常情况,传入的可能不是雪花id那么可以随机查询一张表 //解析雪花id 需要考虑异常情况,传入的可能不是雪花id那么可以直接返回false因为是and链接所以直接就没有结果了//return tail => false;
var analyzeIdToDateTime = SnowflakeId.AnalyzeIdToDateTime(Convert.ToInt64(shardingKey)); var analyzeIdToDateTime = SnowflakeId.AnalyzeIdToDateTime(Convert.ToInt64(shardingKey));
//当前时间的tail //当前时间的tail
var t = TimeFormatToTail(analyzeIdToDateTime); var t = TimeFormatToTail(analyzeIdToDateTime);

View File

@ -0,0 +1,18 @@
using System;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Date: Friday, 05 February 2021 12:53:46
* @Email: 326308290@qq.com
*/
/// <summary>
/// 数据源分库额外规则字段
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class ShardingExtraDataSourceKeyAttribute : Attribute
{
}
}

View File

@ -0,0 +1,18 @@
using System;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Date: Wednesday, 16 December 2020 11:04:51
* @Email: 326308290@qq.com
*/
/// <summary>
/// 分片额外配置
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class ShardingExtraTableKeyAttribute : Attribute
{
}
}

View File

@ -27,7 +27,7 @@ namespace ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions
protected override List<string> DoRouteWithPredicate(List<string> allDataSourceNames, IQueryable queryable) protected override List<string> DoRouteWithPredicate(List<string> allDataSourceNames, IQueryable queryable)
{ {
//获取路由后缀表达式 //获取路由后缀表达式
var routeParseExpression = ShardingUtil.GetRouteParseExpression(queryable, EntityMetadata, GetRouteToFilter, false); var routeParseExpression = ShardingUtil.GetRouteParseExpression(queryable, EntityMetadata, GetRouteFilter, false);
//表达式缓存编译 //表达式缓存编译
var filter = CachingCompile(routeParseExpression); var filter = CachingCompile(routeParseExpression);
//通过编译结果进行过滤 //通过编译结果进行过滤
@ -43,12 +43,12 @@ namespace ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions
/// <param name="shardingOperator">操作</param> /// <param name="shardingOperator">操作</param>
/// <param name="shardingPropertyName">操作</param> /// <param name="shardingPropertyName">操作</param>
/// <returns>如果返回true表示返回该表 第一个参数 tail 第二参数是否返回该物理表</returns> /// <returns>如果返回true表示返回该表 第一个参数 tail 第二参数是否返回该物理表</returns>
public Expression<Func<string, bool>> GetRouteToFilter(object shardingKey, public virtual Expression<Func<string, bool>> GetRouteFilter(object shardingKey,
ShardingOperatorEnum shardingOperator, string shardingPropertyName) ShardingOperatorEnum shardingOperator, string shardingPropertyName)
{ {
if (EntityMetadata.IsMainShardingDataSourceKey(shardingPropertyName)) if (EntityMetadata.IsMainShardingDataSourceKey(shardingPropertyName))
{ {
return GetMainRouteFilter((TKey)shardingKey, shardingOperator); return GetRouteToFilter((TKey)shardingKey, shardingOperator);
} }
else else
{ {
@ -56,7 +56,7 @@ namespace ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions
} }
} }
public abstract Expression<Func<string, bool>> GetMainRouteFilter(TKey shardingKey, public abstract Expression<Func<string, bool>> GetRouteToFilter(TKey shardingKey,
ShardingOperatorEnum shardingOperator); ShardingOperatorEnum shardingOperator);
public virtual Expression<Func<string, bool>> GetExtraRouteFilter(object shardingKey, public virtual Expression<Func<string, bool>> GetExtraRouteFilter(object shardingKey,

View File

@ -37,7 +37,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.Abstractions
/// <param name="shardingOperator">操作</param> /// <param name="shardingOperator">操作</param>
/// <param name="shardingPropertyName">分表字段</param> /// <param name="shardingPropertyName">分表字段</param>
/// <returns>如果返回true表示返回该表 第一个参数 tail 第二参数是否返回该物理表</returns> /// <returns>如果返回true表示返回该表 第一个参数 tail 第二参数是否返回该物理表</returns>
public Expression<Func<string, bool>> GetRouteFilter(object shardingKey, public virtual Expression<Func<string, bool>> GetRouteFilter(object shardingKey,
ShardingOperatorEnum shardingOperator, string shardingPropertyName) ShardingOperatorEnum shardingOperator, string shardingPropertyName)
{ {
if (EntityMetadata.IsMainShardingTableKey(shardingPropertyName)) if (EntityMetadata.IsMainShardingTableKey(shardingPropertyName))

View File

@ -38,6 +38,12 @@ namespace ShardingCore.Helpers
builder.TableSeparator(shardingKey.TableSeparator); builder.TableSeparator(shardingKey.TableSeparator);
shardingTableCount++; shardingTableCount++;
} }
if (attributes.FirstOrDefault(x => x.GetType() == typeof(ShardingExtraTableKeyAttribute)) is
ShardingExtraTableKeyAttribute shardingExtraKey)
{
builder.ShardingExtraProperty(shardingProperty.Name);
}
} }
} }
} }
@ -69,6 +75,11 @@ namespace ShardingCore.Helpers
builder.AutoCreateDataSource(autoCreateDataSource); builder.AutoCreateDataSource(autoCreateDataSource);
shardingDataSourceCount++; shardingDataSourceCount++;
} }
if (attributes.FirstOrDefault(x => x.GetType() == typeof(ShardingExtraDataSourceKeyAttribute)) is
ShardingExtraDataSourceKeyAttribute shardingExtraKey)
{
builder.ShardingExtraProperty(shardingProperty.Name);
}
} }
} }

View File

@ -42,7 +42,7 @@ namespace ShardingCore.Test.Shardings
} }
public override Expression<Func<string, bool>> GetMainRouteFilter(string shardingKey, ShardingOperatorEnum shardingOperator) public override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{ {
var t = ShardingKeyToDataSourceName(shardingKey); var t = ShardingKeyToDataSourceName(shardingKey);

View File

@ -42,7 +42,7 @@ namespace ShardingCore.Test2x.Shardings
} }
public override Expression<Func<string, bool>> GetMainRouteFilter(string shardingKey, ShardingOperatorEnum shardingOperator) public override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{ {
var t = ShardingKeyToDataSourceName(shardingKey); var t = ShardingKeyToDataSourceName(shardingKey);

View File

@ -42,7 +42,7 @@ namespace ShardingCore.Test3x.Shardings
} }
public override Expression<Func<string, bool>> GetMainRouteFilter(string shardingKey, ShardingOperatorEnum shardingOperator) public override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{ {
var t = ShardingKeyToDataSourceName(shardingKey); var t = ShardingKeyToDataSourceName(shardingKey);

View File

@ -42,7 +42,7 @@ namespace ShardingCore.Test5x.Shardings
} }
public override Expression<Func<string, bool>> GetMainRouteFilter(string shardingKey, ShardingOperatorEnum shardingOperator) public override Expression<Func<string, bool>> GetRouteToFilter(string shardingKey, ShardingOperatorEnum shardingOperator)
{ {
var t = ShardingKeyToDataSourceName(shardingKey); var t = ShardingKeyToDataSourceName(shardingKey);