hutongqing
2024-12-10 8d341db9d2d5699d527c88c935f0c4ce255a57a4
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs
@@ -36,38 +36,38 @@
                ISqlSugarClient db = _dbBase;
                //多租户
                var mta = typeof(TEntity).GetCustomAttribute<MultiTenantAttribute>();
                if (mta is { TenantType: TenantTypeEnum.Db })
                {
                    //获取租户信息 ç§Ÿæˆ·ä¿¡æ¯å¯ä»¥æå‰ç¼“存下来
                    if (App.User is { TenantId: > 0 })
                    {
                        dynamic tenant = db.Queryable(MainDb.TenantTableName, "x").Where(MainDb.TenantId, "=", App.User.TenantId).First();
                        if (tenant != null)
                        {
                            var iTenant = db.AsTenant();
                            if (!iTenant.IsAnyConnection(tenant.TenantId))
                            {
                                string conStr = tenant.ConnectionString;
                                ConnectionConfig connectionConfig = new ConnectionConfig()
                                {
                                    ConfigId = tenant.TenantId,
                                    ConnectionString = conStr.DecryptDES(AppSecret.DB),
                                    DbType = (SqlSugar.DbType)tenant.DbType,
                                    IsAutoCloseConnection = true,
                                    AopEvents = new AopEvents()
                                    {
                                        DataExecuting = SqlSugarAop.DataExecuting,
                //var mta = typeof(TEntity).GetCustomAttribute<MultiTenantAttribute>();
                //if (mta is { TenantType: TenantTypeEnum.Db })
                //{
                //    //获取租户信息 ç§Ÿæˆ·ä¿¡æ¯å¯ä»¥æå‰ç¼“存下来
                //    if (App.User is { TenantId: > 0 })
                //    {
                //        dynamic tenant = db.Queryable(MainDb.TenantTableName, "x").Where(MainDb.TenantId, "=", App.User.TenantId).First();
                //        if (tenant != null)
                //        {
                //            var iTenant = db.AsTenant();
                //            if (!iTenant.IsAnyConnection(tenant.TenantId))
                //            {
                //                string conStr = tenant.ConnectionString;
                //                ConnectionConfig connectionConfig = new ConnectionConfig()
                //                {
                //                    ConfigId = tenant.TenantId,
                //                    ConnectionString = conStr.DecryptDES(AppSecret.DB),
                //                    DbType = (SqlSugar.DbType)tenant.DbType,
                //                    IsAutoCloseConnection = true,
                //                    AopEvents = new AopEvents()
                //                    {
                //                        DataExecuting = SqlSugarAop.DataExecuting,
                                    }
                                };
                                iTenant.AddConnection(connectionConfig);
                            }
                //                    }
                //                };
                //                iTenant.AddConnection(connectionConfig);
                //            }
                            return iTenant.GetConnection(tenant.TenantId);
                        }
                    }
                }
                //            return iTenant.GetConnection(tenant.TenantId);
                //        }
                //    }
                //}
                return db;
            }
@@ -124,6 +124,11 @@
            return insert.ExecuteReturnIdentity();
        }
        public virtual bool AddData<TChild>(TEntity entity, Expression<Func<TEntity, List<TChild>>> expression) where TChild : class, new()
        {
            return _db.InsertNav(entity).Include(expression).ExecuteCommand();
        }
        /// <summary>
        /// æ·»åŠ å¤šæ¡æ•°æ®
        /// </summary>