RuoVea.ExSugar
6.0.10
See the version list below for details.
dotnet add package RuoVea.ExSugar --version 6.0.10
NuGet\Install-Package RuoVea.ExSugar -Version 6.0.10
<PackageReference Include="RuoVea.ExSugar" Version="6.0.10" />
paket add RuoVea.ExSugar --version 6.0.10
#r "nuget: RuoVea.ExSugar, 6.0.10"
// Install RuoVea.ExSugar as a Cake Addin #addin nuget:?package=RuoVea.ExSugar&version=6.0.10 // Install RuoVea.ExSugar as a Cake Tool #tool nuget:?package=RuoVea.ExSugar&version=6.0.10
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());
}
/// <summary> /// SqlSugar 启动服务 /// </summary> public static class SqlsugarSetup { public static void AddSqlsugarServer(this IServiceCollection services) { if (services == null) throw new ArgumentNullException(nameof(services)); ConnectionDb config = (ConnectionDb)Appsettings.GetSection("ConnectionStrings").Get(typeof(ConnectionDb)); SqlSugarScope sqlSugar = new SqlSugarScope( SugarUtil.ConnectBuilder(config), db ⇒ { db.Aop.OnLogExecuting = (sql, pars) ⇒ SugarUtil.OnLogExecuting(sql, pars); //执行超时时间 db.Ado.CommandTimeOut = config.CommandTimeOut;
//SQL执行完回调函数
db.Aop.OnLogExecuted = (sql, pars) =>
{
//执行完可以输出SQL执行时间
Console.Write($"SQL:{sql},\r\nTimeSpan:{db.Ado.SqlExecutionTime.TotalMilliseconds}ms\r\n");
};
});
services.AddSingleton<ISqlSugarClient>(sqlSugar);//这边是SqlSugarScope用AddSingleton
}
/// <summary>
/// SqlSugar.IOC注入
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
public static void AddSqlsugarIocSetup(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
var listConfig = new List<IocConfig>();
ConnectionDb config = (ConnectionDb)Appsettings.GetSection("ConnectionStrings").Get(typeof(ConnectionDb));
listConfig.Add(new IocConfig()
{
DbType = (IocDbType)Convert.ToInt32(Enum.Parse(typeof(IocDbType), config.DefaultDbType)),
ConnectionString = config.DefaultDbString,
IsAutoCloseConnection = true,
ConfigId = config.DefaultDbNumber,
});
if (config.DbConfigs != null && config.DbConfigs.Count() > 0)
{
foreach (var item in config.DbConfigs)
{
listConfig.Add(new IocConfig()
{
DbType = (IocDbType)Convert.ToInt32(Enum.Parse(typeof(IocDbType), item.DbType)),
ConnectionString = item.DbString,
IsAutoCloseConnection = true,
ConfigId = item.DbNumber,
});
}
}
services.AddSqlSugar(listConfig);
//配置参数
services.ConfigurationSugar(db =>
{
db.Aop.OnLogExecuting = (sql, pars) => SugarUtil.OnLogExecuting(sql, pars);
if (config.DbConfigs != null && config.DbConfigs.Count() > 0)
{
foreach (var item in config.DbConfigs)
{
db.GetConnection(item.DbNumber).Aop.OnLogExecuting = (sql, pars) => SugarUtil.OnLogExecuting(sql, pars);
}
}
});
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Mapster (>= 7.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- RuoVea.ExConfig (>= 6.0.1)
- RuoVea.ExDto (>= 6.0.9)
- RuoVea.ExEvenBus (>= 6.0.2)
- RuoVea.ExIdGen (>= 6.0.0)
- RuoVea.ExUtil (>= 6.0.12)
- RuoVea.SM (>= 6.0.0)
- SqlSugarCore (>= 5.1.2.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on RuoVea.ExSugar:
Package | Downloads |
---|---|
RuoVea.OmiApi.Config
参数配置接口 |
|
RuoVea.OmiApi.Dict
字典管理 |
|
RuoVea.OmiApi.Log
日志管理 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.0.0.10 | 82 | 11/1/2024 |
8.0.0.9 | 80 | 10/26/2024 |
8.0.0.8 | 71 | 10/25/2024 |
8.0.0.7 | 84 | 10/10/2024 |
8.0.0.6 | 88 | 9/24/2024 |
8.0.0.5 | 92 | 9/22/2024 |
8.0.0.4 | 79 | 9/22/2024 |
8.0.0.3 | 96 | 9/19/2024 |
8.0.0.2 | 109 | 9/11/2024 |
8.0.0.1 | 107 | 8/29/2024 |
8.0.0 | 108 | 8/28/2024 |
7.0.0.10 | 68 | 11/1/2024 |
7.0.0.9 | 72 | 10/26/2024 |
7.0.0.8 | 67 | 10/25/2024 |
7.0.0.7 | 88 | 10/10/2024 |
7.0.0.6 | 80 | 9/24/2024 |
7.0.0.5 | 87 | 9/22/2024 |
7.0.0.4 | 91 | 9/22/2024 |
7.0.0.3 | 87 | 9/19/2024 |
7.0.0.2 | 105 | 9/11/2024 |
7.0.0.1 | 101 | 8/29/2024 |
7.0.0 | 104 | 8/28/2024 |
6.0.18.13 | 1,261 | 11/1/2024 |
6.0.18.12 | 414 | 10/26/2024 |
6.0.18.11 | 76 | 10/25/2024 |
6.0.18.10 | 244 | 10/10/2024 |
6.0.18.9 | 574 | 9/24/2024 |
6.0.18.8 | 161 | 9/22/2024 |
6.0.18.7 | 95 | 9/19/2024 |
6.0.18.6 | 155 | 9/11/2024 |
6.0.18.5 | 112 | 8/29/2024 |
6.0.18.4 | 93 | 8/28/2024 |
6.0.18.3 | 118 | 8/25/2024 |
6.0.18.2 | 139 | 3/13/2024 |
6.0.18.1 | 133 | 3/13/2024 |
6.0.18 | 257 | 3/25/2023 |
6.0.17 | 240 | 3/25/2023 |
6.0.16 | 240 | 3/25/2023 |
6.0.15 | 252 | 3/24/2023 |
6.0.13 | 231 | 3/15/2023 |
6.0.12 | 230 | 3/14/2023 |
6.0.11 | 248 | 3/14/2023 |
6.0.10 | 275 | 3/11/2023 |
6.0.9 | 501 | 8/22/2022 |
6.0.8 | 469 | 8/18/2022 |
6.0.7 | 448 | 8/17/2022 |
6.0.6 | 474 | 8/16/2022 |
6.0.5 | 490 | 7/5/2022 |
6.0.4 | 494 | 7/5/2022 |
6.0.3 | 523 | 6/10/2022 |
6.0.2 | 564 | 4/11/2022 |
6.0.1 | 573 | 4/11/2022 |
6.0.0 | 585 | 3/18/2022 |
5.0.1.5 | 71 | 11/1/2024 |
5.0.1.4 | 75 | 10/26/2024 |
5.0.1.3 | 70 | 10/25/2024 |
5.0.1.2 | 80 | 10/10/2024 |
5.0.1.1 | 87 | 9/24/2024 |
5.0.1 | 642 | 3/18/2022 |
5.0.0 | 559 | 3/18/2022 |