1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
-
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using SqlSugar;
- namespace IoTIntegrationPlatform.Common
- {
- /// <summary>
- /// 静态SqlSugar扩展类
- /// </summary>
- public static class SqlsugarHelper
- {
- /// <summary>
- /// sqlsugarORM框架
- /// </summary>
- /// <param name="service">服务</param>
- /// <param name="configuration">配置文件</param>
- public static void SqlsugarDB(this IServiceCollection service, IConfiguration configuration)
- {
- SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
- {
- DbType = DbType.MySql,
- ConnectionString = configuration.GetConnectionString("SqlConnection"),
- InitKeyType = InitKeyType.Attribute,
- IsAutoCloseConnection = true,
- MoreSettings = new ConnMoreSettings
- {
- PgSqlIsAutoToLower = false
- },
- AopEvents = new AopEvents
- {
- OnLogExecuting = (sql, p) =>
- {
- //Log4NetHelper.WriteLog(null, Log4NetLevel.Info, sql);
- //Logging.Info("执行的sql:"+sql);
- }
- }
- });
- service.AddSingleton<ISqlSugarClient>(sqlSugar);
- }
- }
- }
|