[#232] 修复Nullable<DateTime>类型在比较时导致分片扫描失效的bug无法精确定位

This commit is contained in:
xuejiaming 2023-03-24 15:26:36 +08:00
parent 2253b0f4f7
commit 60ef9f4d6f
3 changed files with 38 additions and 24 deletions

View File

@ -182,14 +182,14 @@ namespace Sample.MySql
// var shardingRuntimeContext = app.ApplicationServices.GetRequiredService<IShardingRuntimeContext>();
// var entityMetadataManager = shardingRuntimeContext.GetEntityMetadataManager();
// var entityMetadata = entityMetadataManager.TryGet<SysUserMod>();
// using (var scope = app.ApplicationServices.CreateScope())
// {
// var defaultShardingDbContext = scope.ServiceProvider.GetService<DefaultShardingDbContext>();
// // if (defaultShardingDbContext.Database.GetPendingMigrations().Any())
// {
// defaultShardingDbContext.Database.Migrate();
// }
// }
using (var scope = app.ApplicationServices.CreateScope())
{
var defaultShardingDbContext = scope.ServiceProvider.GetService<DefaultShardingDbContext>();
// if (defaultShardingDbContext.Database.GetPendingMigrations().Any())
{
defaultShardingDbContext.Database.GenerateCreateScript();
}
}
app.ApplicationServices.UseAutoTryCompensateTable();
// using (var scope = app.ApplicationServices.CreateScope())
// {

View File

@ -102,9 +102,9 @@ namespace ShardingCore.Core.Internal.Visitors
private bool IsShardingKey(Expression expression, out ShardingPredicateResult shardingPredicateResult)
{
MemberExpression realMember = null;
if (expression is MemberExpression member)
{
MemberExpression realMember = null;
if (member.Expression?.Type == _entityMetadata.EntityType)
{
realMember = member;
@ -113,6 +113,18 @@ namespace ShardingCore.Core.Internal.Visitors
{
}
}
else if (expression is UnaryExpression unaryExpression&&
unaryExpression.NodeType == ExpressionType.Convert
)
{
if (unaryExpression.Operand is MemberExpression m &&
m.Expression?.Type == _entityMetadata.EntityType)
{
realMember = m;
}
}
if (realMember != null)
{
var isShardingKey = false;
@ -131,7 +143,6 @@ namespace ShardingCore.Core.Internal.Visitors
return true;
}
}
}
// else if (expression is BinaryExpression binaryExpression)
// {
// if (IsShardingKey(binaryExpression.Left, out shardingPredicateResult))

View File

@ -94,8 +94,11 @@ namespace ShardingCore.CommonTest
var times1 = new List<DateTime>(){queryTime};
var times2 = new []{queryTime,queryTime2};
var obj1 = new {time=new DateTime(2022, 1, 2)};
var dateTime = (DateTime?)new DateTime(2022, 1, 2);
var queryables=new List<IQueryable<TestTimeEntity>>()
{
new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time== dateTime),
new List<TestTimeEntity>().AsQueryable().Where(o=>dateTime==o.Time ),
new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time== new DateTime(2022, 1, 2)),
new List<TestTimeEntity>().AsQueryable().CheckBetween((DateTime?)queryTime,(DateTime?)queryTime3,o=>o.Time),
new List<TestTimeEntity>().AsQueryable().Where(o=>o.Time==times2[0]),