RuoVea.ExSugar 5.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package RuoVea.ExSugar --version 5.0.0
NuGet\Install-Package RuoVea.ExSugar -Version 5.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RuoVea.ExSugar" Version="5.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RuoVea.ExSugar --version 5.0.0
#r "nuget: RuoVea.ExSugar, 5.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RuoVea.ExSugar as a Cake Addin
#addin nuget:?package=RuoVea.ExSugar&version=5.0.0

// Install RuoVea.ExSugar as a Cake Tool
#tool nuget:?package=RuoVea.ExSugar&version=5.0.0

RuoVea.ExSqlSugar

/* 打印sql语句*/ "PrintSql": true,

    private void SqlSugarConfigure(IServiceCollection services)
    {
        #region 配置sqlsuagr
        List<ConnectionConfig> connectConfigList = new List<ConnectionConfig>();
        //数据库序号从0开始,默认数据库为0
        var config= App.GetConfig<ConnectionDb>("ConnectionStrings");
        //默认数据库
        connectConfigList.Add(new ConnectionConfig
        {
            ConnectionString = config.DefaultDbString,
            DbType = (DbType)Convert.ToInt32(Enum.Parse(typeof(DbType), config.DefaultDbType)),
            IsAutoCloseConnection = true,
            ConfigId = config.DefaultDbNumber,
            InitKeyType = InitKeyType.Attribute
        });
        //业务数据库集合
        foreach (var item in config.DbConfigs)
		{
            connectConfigList.Add(new ConnectionConfig
            {
                ConnectionString = item.DbString,
                DbType = (DbType)Convert.ToInt32(Enum.Parse(typeof(DbType), item.DbType)),
                IsAutoCloseConnection = true,
                ConfigId = item.DbNumber,
                InitKeyType = InitKeyType.Attribute
            });
        }
        services.AddSqlSugar(connectConfigList.ToArray()
            , db =>
            {
                db.Aop.OnLogExecuting = (sql, pars) =>
                {
                    if (sql.StartsWith("SELECT"))
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    if (sql.StartsWith("UPDATE") || sql.StartsWith("INSERT"))
                    {
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    if (sql.StartsWith("DELETE"))
                    {
                        Console.ForegroundColor = ConsoleColor.Blue;
                    }
                    //App.PrintToMiniProfiler("SqlSugar", "Info", sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
                    Console.WriteLine(sql + "\r\n\r\n" + SqlProfiler.ParameterFormat(sql, pars));
                    App.PrintToMiniProfiler("SqlSugar", "Info", SqlProfiler.ParameterFormat(sql, pars));
                };
                //执行超时时间
                db.Ado.CommandTimeOut = 30;
                //配置多租户全局过滤器
                db.QueryFilter.Add(new TableFilterItem<SysUser>(FilterExpression<SysUser>()));
                db.QueryFilter.Add(new TableFilterItem<SysOrg>(FilterExpression<SysOrg>()));
                db.QueryFilter.Add(new TableFilterItem<SysPos>(FilterExpression<SysPos>()));
                db.QueryFilter.Add(new TableFilterItem<SysRole>(FilterExpression<SysRole>()));
                db.QueryFilter.Add(new TableFilterItem<OnlineUser>(FilterExpression()));

                // 配置加删除全局过滤器
                db.QueryFilter.Add(new TableFilterItem<SysApp>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysCodeGen>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysCodeGenConfig>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysDictData>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysDictType>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysFile>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysMenu>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysNotice>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysOauthUser>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysOrg>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysPos>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysRole>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysTimer>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysUser>(it => it.IsDeleted == false));
                db.QueryFilter.Add(new TableFilterItem<SysTenant>(it => it.IsDeleted == false));
            });
        #endregion
    }

    /// <summary>
    /// 获取当前租户id
    /// </summary>
    /// <returns></returns>
    private object GetTenantId()
    {
        if (App.User == null) return null;
        return App.User.FindFirst(ClaimConst.TENANT_ID)?.Value;
    }

    /// <summary>
    /// 判断是不是超级管理员
    /// </summary>
    /// <returns></returns>
    private bool IsSuperAdmin()
    {
        if (App.User == null) return false;
        return App.User.FindFirst(ClaimConst.CLAINM_SUPERADMIN)?.Value == AdminType.SuperAdmin.GetHashCode().ToString();
    }

    /// <summary>
    /// 非超级管理员默认添加租户过滤
    /// </summary>
    /// <returns></returns>
    private Expression<Func<T, bool>> FilterExpression<T>() where T : DBEntityTenant
    {
        var superAdminViewAllData = Convert.ToBoolean(App.Configuration["SystemSettings:SuperAdminViewAllData"]);
        if (IsSuperAdmin() && superAdminViewAllData) return m => true;
        return m => m.TenantId == long.Parse(GetTenantId().ToString());
    }

    /// <summary>
    /// 非超级管理员默认添加租户过滤
    /// 在线用户比较特殊,数据库表格设计问题
    /// </summary>
    /// <returns></returns>
    private Expression<Func<OnlineUser, bool>> FilterExpression()
    {
        var superAdminViewAllData = Convert.ToBoolean(App.Configuration["SystemSettings:SuperAdminViewAllData"]);
        if (IsSuperAdmin() && superAdminViewAllData) return m => true;
        return m => m.TenantId == long.Parse(GetTenantId().ToString());
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.18.2 105 3/13/2024
6.0.18.1 104 3/13/2024
6.0.18 238 3/25/2023
6.0.17 210 3/25/2023
6.0.16 210 3/25/2023
6.0.15 223 3/24/2023
6.0.13 219 3/15/2023
6.0.12 206 3/14/2023
6.0.11 224 3/14/2023
6.0.10 231 3/11/2023
6.0.9 464 8/22/2022
6.0.8 449 8/18/2022
6.0.7 414 8/17/2022
6.0.6 434 8/16/2022
6.0.5 469 7/5/2022
6.0.4 474 7/5/2022
6.0.3 486 6/10/2022
6.0.2 534 4/11/2022
6.0.1 537 4/11/2022
6.0.0 557 3/18/2022
5.0.1 615 3/18/2022
5.0.0 544 3/18/2022