修改demo分表分库和code_first
This commit is contained in:
parent
f3cb2b7626
commit
674350b60d
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Sample.AutoCreateIfPresent
|
||||
{
|
||||
[Table("aaa")]
|
||||
public class AreaDevice
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
|
|
@ -109,16 +109,16 @@ namespace Sample.MySql
|
|||
o.UseShardingQuery((conStr, builder) =>
|
||||
{
|
||||
builder.UseMySql(conStr, new MySqlServerVersion(new Version()))
|
||||
.UseLoggerFactory(efLogger)
|
||||
.EnableSensitiveDataLogging()
|
||||
// .UseLoggerFactory(efLogger)
|
||||
// .EnableSensitiveDataLogging()
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
});
|
||||
o.UseShardingTransaction((connection, builder) =>
|
||||
{
|
||||
builder
|
||||
.UseMySql(connection, new MySqlServerVersion(new Version()))
|
||||
.UseLoggerFactory(efLogger)
|
||||
.EnableSensitiveDataLogging()
|
||||
// .UseLoggerFactory(efLogger)
|
||||
// .EnableSensitiveDataLogging()
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
});
|
||||
o.AddDefaultDataSource("ds0",
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"Microsoft": "Debug",
|
||||
"Default": "Information",
|
||||
"Microsoft": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Sample.SqlServerShardingAll
|
|||
},
|
||||
};
|
||||
});
|
||||
}).ReplaceService<ITableEnsureManager,SqlServerTableEnsureManager>().AddShardingCore();
|
||||
}).AddShardingCore();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
@ -75,8 +75,16 @@ namespace Sample.SqlServerShardingAll
|
|||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseShardingCore();
|
||||
//建议补偿表在迁移后面
|
||||
using (var scope = app.ApplicationServices.CreateScope())
|
||||
{
|
||||
var myDbContext = scope.ServiceProvider.GetService<MyDbContext>();
|
||||
//如果没有迁移那么就直接创建表和库
|
||||
myDbContext.Database.EnsureCreated();
|
||||
//如果有迁移使用下面的
|
||||
// myDbContext.Database.Migrate();
|
||||
}
|
||||
app.ApplicationServices.UseAutoTryCompensateTable();
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace Sample.SqlServerShardingDataSource
|
|||
o =>
|
||||
$"Data Source=localhost;Initial Catalog=EFCoreShardingDataSourceOnly{o};Integrated Security=True;");
|
||||
});
|
||||
}).ReplaceService<ITableEnsureManager,SqlServerTableEnsureManager>().AddShardingCore();
|
||||
}).AddShardingCore();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
@ -71,7 +71,16 @@ namespace Sample.SqlServerShardingDataSource
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseShardingCore();
|
||||
//建议补偿表在迁移后面
|
||||
using (var scope = app.ApplicationServices.CreateScope())
|
||||
{
|
||||
var myDbContext = scope.ServiceProvider.GetService<MyDbContext>();
|
||||
//如果没有迁移那么就直接创建表和库
|
||||
myDbContext.Database.EnsureCreated();
|
||||
//如果有迁移使用下面的
|
||||
// myDbContext.Database.Migrate();
|
||||
}
|
||||
app.ApplicationServices.UseAutoTryCompensateTable();
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
|
|
@ -113,6 +113,7 @@ namespace Sample.SqlServerShardingTable
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
//建议补偿表在迁移后面
|
||||
using (var scope = app.ApplicationServices.CreateScope())
|
||||
{
|
||||
var myDbContext = scope.ServiceProvider.GetService<MyDbContext>();
|
||||
|
|
Loading…
Reference in New Issue