Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejmnet committed Jun 20, 2022
1 parent 30d54fd commit 723fa6c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
13 changes: 13 additions & 0 deletions samples/Sample.AutoCreateIfPresent/Controllers/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

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
Expand All @@ -23,6 +28,14 @@ public IActionResult HelloWorld()

public async Task<IActionResult> Query()
{
var aas = new List<AA>();
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<OrderByHour>().ToListAsync();
return Ok(list);
}
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample.MySql/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void ConfigureServices(IServiceCollection services)
{
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<DefaultShardingDbContext>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,23 @@ public virtual Task ExecuteAsync()
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 ");
}
}
}
}
Expand Down

0 comments on commit 723fa6c

Please sign in to comment.