Skip to content

Commit 723fa6c

Browse files
committed
修复bug
1 parent 30d54fd commit 723fa6c

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

samples/Sample.AutoCreateIfPresent/Controllers/TestController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
namespace Sample.AutoCreateIfPresent.Controllers;
55

6+
public class AA
7+
{
8+
public string Id { get; set; }
9+
public DateTime Time { get; set; }
10+
}
611
[ApiController]
712
[Route("[controller]/[action]")]
813
public class TestController : ControllerBase
@@ -23,6 +28,14 @@ public IActionResult HelloWorld()
2328

2429
public async Task<IActionResult> Query()
2530
{
31+
var aas = new List<AA>();
32+
var ids = new []{"雪花id1","雪花id2"};
33+
var time1 = new DateTime(2021,1,1);
34+
var time2 = new DateTime(2022,1,1);
35+
var enumerable = aas.Where(o=>ids.Contains(o.Id)&&o.Time>=time1&&o.Time<=time2);
36+
var enumerable1 = aas.Where(o=>o.Id=="雪花id1"||o.Id=="雪花id2");
37+
var enumerable2 = aas.Where(o=>o.Id=="雪花id1"&&o.Id=="雪花id2");
38+
2639
var list =await _defaultDbContext.Set<OrderByHour>().ToListAsync();
2740
return Ok(list);
2841
}

samples/Sample.MySql/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void ConfigureServices(IServiceCollection services)
6969
{
7070
op.ConfigId = "c1";
7171
op.AddDefaultDataSource("ds0",
72-
"server=127.0.0.1;port=3306;database=dbxxxx;userid=root;password=root;");
72+
"server=127.0.0.1;port=3307;database=dbxxxx;userid=root;password=root;");
7373

7474
//op.AddDefaultDataSource("ds0", "server=127.0.0.1;port=3306;database=db2;userid=root;password=L6yBtV6qNENrwBy7;")
7575
op.ReplaceTableEnsureManager(sp=>new MySqlTableEnsureManager<DefaultShardingDbContext>());

src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,23 @@ public virtual Task ExecuteAsync()
9292
dataSources.Add(virtualDataSource.DefaultDataSourceName);
9393
}
9494
_logger.LogInformation($"auto create table data source names:[{string.Join(",", dataSources)}]");
95-
foreach (var dataSource in dataSources)
95+
using (virtualDataSourceManager.CreateScope(virtualDataSource.ConfigId))
9696
{
97-
try
97+
foreach (var dataSource in dataSources)
9898
{
99-
_logger.LogInformation($"begin table tail:[{tail}],entity:[{typeof(TEntity).Name}]");
100-
tableCreator.CreateTable(dataSource, typeof(TEntity), tail);
101-
_logger.LogInformation($"succeed table tail:[{tail}],entity:[{typeof(TEntity).Name}]");
102-
}
103-
catch (Exception e)
104-
{
105-
//ignore
106-
_logger.LogInformation($"warning table tail:[{tail}],entity:[{typeof(TEntity).Name}]");
107-
if (DoLogError)
108-
_logger.LogError(e, $"{dataSource} {typeof(TEntity).Name}'s create table error ");
99+
try
100+
{
101+
_logger.LogInformation($"begin table tail:[{tail}],entity:[{typeof(TEntity).Name}]");
102+
tableCreator.CreateTable(dataSource, typeof(TEntity), tail);
103+
_logger.LogInformation($"succeed table tail:[{tail}],entity:[{typeof(TEntity).Name}]");
104+
}
105+
catch (Exception e)
106+
{
107+
//ignore
108+
_logger.LogInformation($"warning table tail:[{tail}],entity:[{typeof(TEntity).Name}]");
109+
if (DoLogError)
110+
_logger.LogError(e, $"{dataSource} {typeof(TEntity).Name}'s create table error ");
111+
}
109112
}
110113
}
111114
}

0 commit comments

Comments
 (0)