From 723fa6ca42c4b371f69b17b790a26886a56e3e09 Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Mon, 20 Jun 2022 15:43:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/TestController.cs | 13 +++++++++ samples/Sample.MySql/Startup.cs | 2 +- ...dingAutoCreateOperatorVirtualTableRoute.cs | 27 ++++++++++--------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/samples/Sample.AutoCreateIfPresent/Controllers/TestController.cs b/samples/Sample.AutoCreateIfPresent/Controllers/TestController.cs index 2679af70..3360e173 100644 --- a/samples/Sample.AutoCreateIfPresent/Controllers/TestController.cs +++ b/samples/Sample.AutoCreateIfPresent/Controllers/TestController.cs @@ -3,6 +3,11 @@ using Microsoft.EntityFrameworkCore; namespace Sample.AutoCreateIfPresent.Controllers; +public class AA +{ + public string Id { get; set; } + public DateTime Time { get; set; } +} [ApiController] [Route("[controller]/[action]")] public class TestController : ControllerBase @@ -23,6 +28,14 @@ public class TestController : ControllerBase public async Task Query() { + var aas = new List(); + var ids = new []{"雪花id1","雪花id2"}; + var time1 = new DateTime(2021,1,1); + var time2 = new DateTime(2022,1,1); + var enumerable = aas.Where(o=>ids.Contains(o.Id)&&o.Time>=time1&&o.Time<=time2); + var enumerable1 = aas.Where(o=>o.Id=="雪花id1"||o.Id=="雪花id2"); + var enumerable2 = aas.Where(o=>o.Id=="雪花id1"&&o.Id=="雪花id2"); + var list =await _defaultDbContext.Set().ToListAsync(); return Ok(list); } diff --git a/samples/Sample.MySql/Startup.cs b/samples/Sample.MySql/Startup.cs index 29f92142..5b184e35 100644 --- a/samples/Sample.MySql/Startup.cs +++ b/samples/Sample.MySql/Startup.cs @@ -69,7 +69,7 @@ namespace Sample.MySql { op.ConfigId = "c1"; op.AddDefaultDataSource("ds0", - "server=127.0.0.1;port=3306;database=dbxxxx;userid=root;password=root;"); + "server=127.0.0.1;port=3307;database=dbxxxx;userid=root;password=root;"); //op.AddDefaultDataSource("ds0", "server=127.0.0.1;port=3306;database=db2;userid=root;password=L6yBtV6qNENrwBy7;") op.ReplaceTableEnsureManager(sp=>new MySqlTableEnsureManager()); diff --git a/src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs b/src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs index 1407f927..37626ccb 100644 --- a/src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs +++ b/src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs @@ -92,20 +92,23 @@ namespace ShardingCore.VirtualRoutes.Abstractions dataSources.Add(virtualDataSource.DefaultDataSourceName); } _logger.LogInformation($"auto create table data source names:[{string.Join(",", dataSources)}]"); - foreach (var dataSource in dataSources) + using (virtualDataSourceManager.CreateScope(virtualDataSource.ConfigId)) { - try + foreach (var dataSource in dataSources) { - _logger.LogInformation($"begin table tail:[{tail}],entity:[{typeof(TEntity).Name}]"); - tableCreator.CreateTable(dataSource, typeof(TEntity), tail); - _logger.LogInformation($"succeed table tail:[{tail}],entity:[{typeof(TEntity).Name}]"); - } - catch (Exception e) - { - //ignore - _logger.LogInformation($"warning table tail:[{tail}],entity:[{typeof(TEntity).Name}]"); - if (DoLogError) - _logger.LogError(e, $"{dataSource} {typeof(TEntity).Name}'s create table error "); + try + { + _logger.LogInformation($"begin table tail:[{tail}],entity:[{typeof(TEntity).Name}]"); + tableCreator.CreateTable(dataSource, typeof(TEntity), tail); + _logger.LogInformation($"succeed table tail:[{tail}],entity:[{typeof(TEntity).Name}]"); + } + catch (Exception e) + { + //ignore + _logger.LogInformation($"warning table tail:[{tail}],entity:[{typeof(TEntity).Name}]"); + if (DoLogError) + _logger.LogError(e, $"{dataSource} {typeof(TEntity).Name}'s create table error "); + } } } }