From 32ed6c3e975a702ee4bca9c4c5ce549e80b7111c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Wed, 2 Nov 2022 11:06:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=86=E5=A4=87=E6=8E=A5=E5=85=A5Saas?= =?UTF-8?q?=E5=A4=9A=E7=A7=9F=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Yi.Framework.Repository/Repository.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs index 1bf2dc4e..7973c181 100644 --- a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs +++ b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs @@ -16,6 +16,7 @@ namespace Yi.Framework.Repository [AppService] public class Repository : SimpleClient, IRepository where T : class, new() { + public ISugarQueryable _DbQueryable { get { return base.Context.Queryable(); } set { } } public ISqlSugarClient _Db { get { return base.Context; } set { } } @@ -25,6 +26,21 @@ namespace Yi.Framework.Repository /// public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null { + //开始Saas分库! + //单个公共基础库+多个租户业务库 + + //1:先判断操作对应实体上是否存在租户特性,如果存在说明是公共库 + + //如果是公共库,直接使用默认库即可 + //如果不是公共库 + + //2:根据上下文对象获取用户的租户id + //3:根据租户id获取到对应上下文对象 + //4:替换仓储中的上下文对象即可 + + //强化:如果租户要做到动态配置不写死,租户信息连接字符串等存入数据库,带入token中,还需要在sqlsugarAop中动态获取进行切换 + //base.Context = context.AsTenant().GetConnectionScopeWithAttr(); + } ///