-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
363 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Linq; | ||
using SqlSugar; | ||
|
||
namespace Blog.Core.Common.DB.Aop; | ||
|
||
public class SqlSugarReuse | ||
{ | ||
public static void AutoChangeAvailableConnect(SqlSugarClient db) | ||
{ | ||
if (db == null) return; | ||
if (db.Ado.IsValidConnection()) return; | ||
if (!BaseDBConfig.ReuseConfigs.Any()) return; | ||
|
||
foreach (var connectionConfig in BaseDBConfig.ReuseConfigs) | ||
{ | ||
var config = db.CurrentConnectionConfig.ConfigId; | ||
db.ChangeDatabase(connectionConfig.ConfigId); | ||
//移除旧的连接,只会在本次上下文移除,因为主库已经故障会导致多库事务无法使用 | ||
db.RemoveConnection(config); | ||
if (db.Ado.IsValidConnection()) return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Reflection; | ||
using SqlSugar; | ||
|
||
namespace Blog.Core.Common.DB.Extension; | ||
|
||
public static class DbEntityException | ||
{ | ||
public static object GetEntityTenant(this Type type) | ||
{ | ||
var tenant = type.GetCustomAttribute<TenantAttribute>(); | ||
return tenant?.configId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.