mirror of
https://github.com/anjoy8/Blog.Core.git
synced 2024-09-20 23:48:27 +08:00
//修改使用 model备注字段作为切换数据库条件,使用sqlsugar TenantAttribute存放数据库ConnId
This commit is contained in:
parent
2fbd8ac856
commit
26d97687b1
|
@ -7,7 +7,8 @@ namespace Blog.Core.Model.IDS4DbModels
|
|||
/// 以下model 来自ids4项目,多库模式,为了调取ids4数据
|
||||
/// 角色表
|
||||
/// </summary>
|
||||
[SugarTable("ApplicationRole", "WMBLOG_MYSQL_2")]
|
||||
[SugarTable("ApplicationRole", "角色表")] //('数据库表名','数据库表备注')
|
||||
[TenantAttribute("WMBLOG_MYSQL_2")] //('代表是哪个数据库,名字是appsettings.json 的 ConnId')
|
||||
public class ApplicationRole
|
||||
{
|
||||
public bool IsDeleted { get; set; }
|
||||
|
|
|
@ -7,7 +7,8 @@ namespace Blog.Core.Model.IDS4DbModels
|
|||
/// 以下model 来自ids4项目,多库模式,为了调取ids4数据
|
||||
/// 用户表
|
||||
/// </summary>
|
||||
[SugarTable("AspNetUsers", "WMBLOG_MYSQL_2")]
|
||||
[SugarTable("AspNetUsers", "用户表")]//('数据库表名','数据库表备注')
|
||||
[TenantAttribute("WMBLOG_MYSQL_2")] //('代表是哪个数据库,名字是appsettings.json 的 ConnId')
|
||||
public class ApplicationUser
|
||||
{
|
||||
public string LoginName { get; set; }
|
||||
|
|
|
@ -6,7 +6,8 @@ namespace Blog.Core.Model.Models
|
|||
/// <summary>
|
||||
/// 密码库表
|
||||
/// </summary>
|
||||
[SugarTable("PasswordLib", "WMBLOG_MSSQL_2")]
|
||||
[SugarTable("PasswordLib", "密码库表")]//('数据库表名','数据库表备注')
|
||||
[TenantAttribute("WMBLOG_MYSQL_2")] //('代表是哪个数据库,名字是appsettings.json 的 ConnId')
|
||||
public class PasswordLib
|
||||
{
|
||||
[SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true)]
|
||||
|
|
|
@ -28,16 +28,24 @@ namespace Blog.Core.Repository.Base
|
|||
*/
|
||||
if (Appsettings.app(new string[] { "MutiDBEnabled" }).ObjToBool())
|
||||
{
|
||||
if (typeof(TEntity).GetTypeInfo().GetCustomAttributes(typeof(SugarTable), true).FirstOrDefault((x => x.GetType() == typeof(SugarTable))) is SugarTable sugarTable && !string.IsNullOrEmpty(sugarTable.TableDescription))
|
||||
//if (typeof(TEntity).GetTypeInfo().GetCustomAttributes(typeof(SugarTable), true).FirstOrDefault((x => x.GetType() == typeof(SugarTable))) is SugarTable sugarTable && !string.IsNullOrEmpty(sugarTable.TableDescription))
|
||||
//{
|
||||
// _dbBase.ChangeDatabase(sugarTable.TableDescription.ToLower());
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// _dbBase.ChangeDatabase(MainDb.CurrentDbConnId.ToLower());
|
||||
//}
|
||||
//修改使用 model备注字段作为切换数据库条件,使用sqlsugar TenantAttribute存放数据库ConnId
|
||||
if (typeof(TEntity).GetTypeInfo().GetCustomAttributes(typeof(TenantAttribute), true).FirstOrDefault((x => x.GetType() == typeof(TenantAttribute))) is TenantAttribute tenantAttribute)
|
||||
{
|
||||
_dbBase.ChangeDatabase(sugarTable.TableDescription.ToLower());
|
||||
_dbBase.ChangeDatabase(tenantAttribute.configId.ToString().ToLower());
|
||||
}
|
||||
else
|
||||
{
|
||||
_dbBase.ChangeDatabase(MainDb.CurrentDbConnId.ToLower());
|
||||
}
|
||||
}
|
||||
|
||||
return _dbBase;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user