移除mysql的多余dbcontext

This commit is contained in:
xuejiaming 2022-09-21 21:56:59 +08:00
parent bbf88d97f5
commit 071a9c9971
5 changed files with 58 additions and 31 deletions

View File

@ -43,7 +43,7 @@ namespace Sample.MySql.Controllers
[HttpGet]
public async Task<IActionResult> Get()
{
OtherDbContext.CurrentId = "";
//OtherDbContext.CurrentId = "";
// var myUsers0 = _otherDbContext.MyUsers.ToList();
// OtherDbContext.CurrentId = "123";
// var myUsers1 = _otherDbContext.MyUsers.ToList();

View File

@ -54,7 +54,7 @@ namespace Sample.MySql
public void ConfigureServices(IServiceCollection services)
{
// services.AddHostedService<AutoStart>();
services.AddControllers();
services.AddControllers();
// services.AddShardingDbContext<ShardingDefaultDbContext, DefaultDbContext>(o => o.UseMySql(hostBuilderContext.Configuration.GetSection("MySql")["ConnectionString"],new MySqlServerVersion("5.7.15"))
// ,op =>
// {

View File

@ -1,26 +1,26 @@
using Microsoft.EntityFrameworkCore;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.Sharding;
using ShardingCore.Sharding.Abstractions;
//using Microsoft.EntityFrameworkCore;
//using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
//using ShardingCore.Sharding;
//using ShardingCore.Sharding.Abstractions;
namespace Sample.MySql.multi;
//namespace Sample.MySql.multi;
public class OtherDbContext:AbstractShardingDbContext,IShardingTableDbContext
{
public DbSet<MyUser> MyUsers { get; set; }
public OtherDbContext(DbContextOptions<OtherDbContext> options) : base(options)
{
}
//public class OtherDbContext:AbstractShardingDbContext,IShardingTableDbContext
//{
// public DbSet<MyUser> MyUsers { get; set; }
// public OtherDbContext(DbContextOptions<OtherDbContext> options) : base(options)
// {
// }
public static string CurrentId;
public string CID => CurrentId;
public bool HasCID => !string.IsNullOrWhiteSpace(CID);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<MyUser>()
.HasQueryFilter(o => !HasCID || o.Id == CID);
}
// public static string CurrentId;
// public string CID => CurrentId;
// public bool HasCID => !string.IsNullOrWhiteSpace(CID);
// protected override void OnModelCreating(ModelBuilder modelBuilder)
// {
// base.OnModelCreating(modelBuilder);
// modelBuilder.Entity<MyUser>()
// .HasQueryFilter(o => !HasCID || o.Id == CID);
// }
public IRouteTail RouteTail { get; set; }
}
// public IRouteTail RouteTail { get; set; }
//}

View File

@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:1129/",
"sslPort": 44318
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Sample.OracleIssue": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}

View File

@ -1,11 +1,11 @@
{
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:34492",
"sslPort": 44389
"applicationUrl": "http://localhost:1125/",
"sslPort": 44366
}
},
"profiles": {
@ -19,13 +19,13 @@
},
"Samples.AutoByDate.SqlServer": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"dotnetRunMessages": "true"
}
}
}
}