修复net6访问未分表表名bug

This commit is contained in:
xuejiaming 2021-11-22 11:03:25 +08:00
parent 1950a5c0ec
commit 273c7504e8
29 changed files with 52 additions and 512 deletions

View File

@ -1,9 +1,9 @@
:start
::定义版本
set EFCORE2=2.3.1.42
set EFCORE3=3.3.1.42
set EFCORE5=5.3.1.42
set EFCORE6=6.3.1.42
set EFCORE2=2.3.1.44
set EFCORE3=3.3.1.44
set EFCORE5=5.3.1.44
set EFCORE6=6.3.1.44
::删除所有bin与obj下的文件
@echo off

View File

@ -32,6 +32,18 @@ namespace Sample.SqlServer.Controllers
_shardingRouteManager = shardingRouteManager;
}
[HttpGet]
public async Task<IActionResult> Get2x()
{
await _defaultTableDbContext.AddAsync(new SysUserMod()
{
Id = Guid.NewGuid().ToString("n"),
Age = 9,
AgeGroup = 10, Name = "SysUserModTest"
});
await _defaultTableDbContext.SaveChangesAsync();
return Ok();
}
[HttpGet]
public async Task<IActionResult> Get()
{

View File

@ -85,6 +85,7 @@ namespace ShardingCore.Bootstrapers
}
_virtualDataSource.AddVirtualDataSourceRoute(dataSourceRoute);
entityMetadata.CheckShardingDataSourceMetadata();
}
if (_shardingConfigOption.TryGetVirtualTableRoute<TEntity>(out var virtualTableRouteType))
@ -107,7 +108,7 @@ namespace ShardingCore.Bootstrapers
var virtualTable = CreateVirtualTable(virtualTableRoute,entityMetadata);
_virtualTableManager.AddVirtualTable(virtualTable);
//检测校验分表分库对象元数据
entityMetadata.CheckMetadata();
entityMetadata.CheckShardingTableMetadata();
//添加任务
if (virtualTableRoute is IJob routeJob && routeJob.StartJob())
{
@ -116,6 +117,7 @@ namespace ShardingCore.Bootstrapers
jobManager.AddJob(jobEntry);
}
}
entityMetadata.CheckGenericMetadata();
}
private IVirtualDataSourceRoute<TEntity> CreateVirtualDataSourceRoute(Type virtualRouteType,EntityMetadata entityMetadata)

View File

@ -99,7 +99,29 @@ namespace ShardingCore.Core.EntityMetadatas
TableSeparator = separator;
}
public void CheckMetadata()
public void CheckShardingDataSourceMetadata()
{
if (!IsMultiDataSourceMapping)
{
throw new ShardingCoreException($"not found entity:{EntityType} configure");
}
if(ShardingDataSourceProperty==null)
{
throw new ShardingCoreException($"not found entity:{EntityType} configure sharding property");
}
}
public void CheckShardingTableMetadata()
{
if (!IsMultiTableMapping)
{
throw new ShardingCoreException($"not found entity:{EntityType} configure");
}
if (ShardingTableProperty == null)
{
throw new ShardingCoreException($"not found entity:{EntityType} configure sharding property");
}
}
public void CheckGenericMetadata()
{
if (null == EntityType || null == PrimaryKeyProperties || null == VirtualTableName ||
(!IsMultiTableMapping && !IsMultiDataSourceMapping))

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Monday, 28 December 2020 22:34:00
* @Email: 326308290@qq.com
*/
public class CreateSqlVirtualTableNotFoundException:Exception
{
public CreateSqlVirtualTableNotFoundException()
{
}
protected CreateSqlVirtualTableNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public CreateSqlVirtualTableNotFoundException(string message) : base(message)
{
}
public CreateSqlVirtualTableNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Friday, 15 January 2021 09:07:34
* @Email: 326308290@qq.com
*/
public class InvalidReplaceQueryRootException:Exception
{
public InvalidReplaceQueryRootException()
{
}
protected InvalidReplaceQueryRootException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public InvalidReplaceQueryRootException(string message) : base(message)
{
}
public InvalidReplaceQueryRootException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Friday, 18 December 2020 21:36:24
* @Email: 326308290@qq.com
*/
public class QueryableRouteNotMatchException:Exception
{
public QueryableRouteNotMatchException()
{
}
protected QueryableRouteNotMatchException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public QueryableRouteNotMatchException(string message) : base(message)
{
}
public QueryableRouteNotMatchException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: 2021/3/5 8:11:30
* @Ver: 1.0
* @Email: 326308290@qq.com
*/
public class ShardingConfigNotFoundException:Exception
{
public ShardingConfigNotFoundException()
{
}
protected ShardingConfigNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingConfigNotFoundException(string message) : base(message)
{
}
public ShardingConfigNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,31 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Wednesday, 25 August 2021 19:20:14
* @Email: 326308290@qq.com
*/
public class ShardingCoreAssertException:ShardingCoreException
{
public ShardingCoreAssertException()
{
}
protected ShardingCoreAssertException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingCoreAssertException(string message) : base(message)
{
}
public ShardingCoreAssertException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -9,20 +9,9 @@ namespace ShardingCore.Exceptions
{
public class ShardingCoreInvalidOperationException: ShardingCoreException
{
public ShardingCoreInvalidOperationException()
{
}
protected ShardingCoreInvalidOperationException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingCoreInvalidOperationException(string? message) : base(message)
{
}
public ShardingCoreInvalidOperationException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: 2021/9/16 14:08:08
* @Ver: 1.0
* @Email: 326308290@qq.com
*/
public class ShardingCoreNotSupportedException:NotSupportedException
{
public ShardingCoreNotSupportedException()
{
}
protected ShardingCoreNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingCoreNotSupportedException(string message) : base(message)
{
}
public ShardingCoreNotSupportedException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -14,20 +14,9 @@ namespace ShardingCore.Exceptions
*/
public class ShardingCoreParallelQueryTimeOutException:ShardingCoreException
{
public ShardingCoreParallelQueryTimeOutException()
{
}
protected ShardingCoreParallelQueryTimeOutException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingCoreParallelQueryTimeOutException(string message) : base(message)
{
}
public ShardingCoreParallelQueryTimeOutException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -9,19 +9,8 @@ namespace ShardingCore.Exceptions
* @Date: Wednesday, 13 January 2021 10:20:47
* @Email: 326308290@qq.com
*/
public class ShardingCreateException:Exception
public class ShardingCreateException:ShardingCoreException
{
public ShardingCreateException()
{
}
protected ShardingCreateException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingCreateException(string message) : base(message)
{
}
public ShardingCreateException(string message, Exception innerException) : base(message, innerException)
{

View File

@ -11,20 +11,9 @@ namespace ShardingCore.Exceptions
*/
public class ShardingDataSourceNotFoundException:ShardingCoreException
{
public ShardingDataSourceNotFoundException()
{
}
protected ShardingDataSourceNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingDataSourceNotFoundException(string message) : base(message)
{
}
public ShardingDataSourceNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Saturday, 06 February 2021 09:08:49
* @Email: 326308290@qq.com
*/
public class ShardingDataSourceRouteMatchMoreException:Exception
{
public ShardingDataSourceRouteMatchMoreException()
{
}
protected ShardingDataSourceRouteMatchMoreException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingDataSourceRouteMatchMoreException(string message) : base(message)
{
}
public ShardingDataSourceRouteMatchMoreException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -9,22 +9,10 @@ namespace ShardingCore.Exceptions
* @Date: Saturday, 06 February 2021 09:07:39
* @Email: 326308290@qq.com
*/
public class ShardingDataSourceRouteNotMatchException:Exception
public class ShardingDataSourceRouteNotMatchException:ShardingCoreException
{
public ShardingDataSourceRouteNotMatchException()
{
}
protected ShardingDataSourceRouteNotMatchException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingDataSourceRouteNotMatchException(string message) : base(message)
{
}
public ShardingDataSourceRouteNotMatchException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Wednesday, 23 December 2020 09:11:57
* @Email: 326308290@qq.com
*/
public class ShardingEntityTypeConfiguration404Exception:Exception
{
public ShardingEntityTypeConfiguration404Exception()
{
}
protected ShardingEntityTypeConfiguration404Exception(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingEntityTypeConfiguration404Exception(string message) : base(message)
{
}
public ShardingEntityTypeConfiguration404Exception(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -9,22 +9,10 @@ namespace ShardingCore.Exceptions
* @Date: Wednesday, 13 January 2021 11:09:33
* @Email: 326308290@qq.com
*/
public class ShardingKeyGetValueException:Exception
public class ShardingKeyGetValueException:ShardingCoreException
{
public ShardingKeyGetValueException()
{
}
protected ShardingKeyGetValueException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingKeyGetValueException(string message) : base(message)
{
}
public ShardingKeyGetValueException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -9,22 +9,11 @@ namespace ShardingCore.Exceptions
* @Date: Saturday, 19 December 2020 16:25:21
* @Email: 326308290@qq.com
*/
public class ShardingKeyRouteMoreException:Exception
public class ShardingKeyRouteMoreException:ShardingCoreException
{
public ShardingKeyRouteMoreException()
{
}
protected ShardingKeyRouteMoreException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingKeyRouteMoreException(string message) : base(message)
{
}
public ShardingKeyRouteMoreException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -11,20 +11,9 @@ namespace ShardingCore.Exceptions
*/
public class ShardingKeyRouteNotMatchException:Exception
{
public ShardingKeyRouteNotMatchException()
{
}
protected ShardingKeyRouteNotMatchException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingKeyRouteNotMatchException(string message) : base(message)
{
}
public ShardingKeyRouteNotMatchException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Friday, 18 December 2020 10:40:34
* @Email: 326308290@qq.com
*/
public class ShardingTransactionException:Exception
{
public ShardingTransactionException()
{
}
protected ShardingTransactionException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingTransactionException(string message) : base(message)
{
}
public ShardingTransactionException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -12,22 +12,11 @@ namespace ShardingCore.Exceptions
* @Ver: 1.0
* @Email: 326308290@qq.com
*/
public class ShardingVirtualTableNotFoundException: Exception
public class ShardingVirtualTableNotFoundException: ShardingCoreException
{
public ShardingVirtualTableNotFoundException()
{
}
protected ShardingVirtualTableNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ShardingVirtualTableNotFoundException(string message) : base(message)
{
}
public ShardingVirtualTableNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Saturday, 06 February 2021 15:41:19
* @Email: 326308290@qq.com
*/
public class VirtualDataSourceNotFoundException:Exception
{
public VirtualDataSourceNotFoundException()
{
}
protected VirtualDataSourceNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public VirtualDataSourceNotFoundException(string message) : base(message)
{
}
public VirtualDataSourceNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Monday, 21 December 2020 09:50:57
* @Email: 326308290@qq.com
*/
public class VirtualRouteNotFoundException:Exception
{
public VirtualRouteNotFoundException()
{
}
protected VirtualRouteNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public VirtualRouteNotFoundException(string message) : base(message)
{
}
public VirtualRouteNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Friday, 18 December 2020 15:38:02
* @Email: 326308290@qq.com
*/
public class VirtualRouteNotMatchException:Exception
{
public VirtualRouteNotMatchException()
{
}
protected VirtualRouteNotMatchException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public VirtualRouteNotMatchException(string message) : base(message)
{
}
public VirtualRouteNotMatchException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -1,30 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace ShardingCore.Exceptions
{
/*
* @Author: xjm
* @Description:
* @Date: Friday, 18 December 2020 15:01:16
* @Email: 326308290@qq.com
*/
public class VirtualTableNotFoundException:Exception
{
public VirtualTableNotFoundException()
{
}
protected VirtualTableNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public VirtualTableNotFoundException(string message) : base(message)
{
}
public VirtualTableNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
}

View File

@ -132,6 +132,8 @@ namespace ShardingCore.Extensions
IMemoryCache memoryCache = modelSourceDependencies.MemoryCache;
object key1 = modelSourceDependencies.ModelCacheKeyFactory.Create(dbContext,true);
memoryCache.Remove(key1);
object key2 = modelSourceDependencies.ModelCacheKeyFactory.Create(dbContext,false);
memoryCache.Remove(key2);
#endif
#if EFCORE5
var dependencies = dbContext.GetService<IModelCreationDependencies>();

View File

@ -158,9 +158,9 @@ namespace ShardingCore.Sharding.ShardingDbContextExecutors
public DbContext CreateDbContext(IRouteTail routeTail)
{
if (routeTail.IsMultiEntityQuery())
throw new ShardingCoreNotSupportedException("multi route not support track");
throw new NotSupportedException("multi route not support track");
if (!(routeTail is ISingleQueryRouteTail singleQueryRouteTail))
throw new ShardingCoreNotSupportedException("multi route not support track");
throw new NotSupportedException("multi route not support track");
var cacheKey = routeTail.GetRouteTailIdentity();
if (!_dataSourceDbContexts.TryGetValue(cacheKey, out var dbContext))

View File

@ -83,7 +83,7 @@ namespace ShardingCore.Core.Internal.Visitors
if (node is QueryRootExpression queryRootExpression)
{
if (QueryRootExpression != null)
throw new InvalidReplaceQueryRootException("more than one query root");
throw new ShardingCoreException("replace query root more than one query root");
QueryRootExpression = queryRootExpression;
}