diff --git a/ZR.Admin.WebApi/Controllers/business/GendemoController.cs b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs index 33c8a37..077ca73 100644 --- a/ZR.Admin.WebApi/Controllers/business/GendemoController.cs +++ b/ZR.Admin.WebApi/Controllers/business/GendemoController.cs @@ -51,7 +51,7 @@ namespace ZR.Admin.WebApi.Controllers //TODO 搜索条件 //predicate = predicate.And(m => m.Name.Contains(parm.Name)); - + _GendemoService.Test(); var response = _GendemoService.GetPages(predicate.ToExpression(), parm); return SUCCESS(response); diff --git a/ZR.Admin.WebApi/Startup.cs b/ZR.Admin.WebApi/Startup.cs index a5cff2e..3de82bb 100644 --- a/ZR.Admin.WebApi/Startup.cs +++ b/ZR.Admin.WebApi/Startup.cs @@ -164,6 +164,14 @@ namespace ZR.Admin.WebApi Console.WriteLine($"[ִSql]{e.Message}SQL={e.Sql}"); Console.WriteLine(); }; + + //ʽ ӡSQL + DbScoped.SugarScope.GetConnection(1).Aop.OnLogExecuting = (sql, pars) => + { + Console.BackgroundColor = ConsoleColor.Yellow; + Console.WriteLine("SQLBus" + sql.ToLower() + "\r\n" + + DbScoped.SugarScope.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); + }; //Bus Db־ DbScoped.SugarScope.GetConnection(1).Aop.OnError = (e) => { diff --git a/ZR.Repository/BaseRepository.cs b/ZR.Repository/BaseRepository.cs index 5e051bf..43125f0 100644 --- a/ZR.Repository/BaseRepository.cs +++ b/ZR.Repository/BaseRepository.cs @@ -1,13 +1,9 @@ -using Infrastructure; -using Infrastructure.Model; +using Infrastructure.Model; using SqlSugar; using SqlSugar.IOC; using System; using System.Collections.Generic; -using System.Dynamic; -using System.Linq; using System.Linq.Expressions; -using System.Threading.Tasks; using ZR.Model; namespace ZR.Repository @@ -19,34 +15,11 @@ namespace ZR.Repository public class BaseRepository : IBaseRepository where T : class, new() { public ISqlSugarClient Context; - //private ISqlSugarClient _db - //{ - // get - // { - // if (typeof(T).GetTypeInfo().GetCustomAttributes(typeof(SugarTable), true).FirstOrDefault((x => x.GetType() == typeof(SugarTable))) is SugarTable sugarTable && !string.IsNullOrEmpty(sugarTable.TableDescription)) - // { - // Context.ChangeDatabase(sugarTable.TableDescription.ToLower()); - // } - // else - // { - // Context.ChangeDatabase(0); - // } - - // return Context; - // } - //} - public BaseRepository(ISqlSugarClient dbContext = null, string configId = "0") //: base(dbContext) + public BaseRepository(string configId = "0") //: base(dbContext) { - if (dbContext == null) - { - Context = DbScoped.SugarScope.GetConnection(configId);//根据类传入的ConfigId自动选择 - //_dbbase = Context; - } + Context = DbScoped.SugarScope.GetConnection(configId);//根据类传入的ConfigId自动选择 } - //public ISqlSugarClient Db - //{ - // get { return _db; } - //} + #region add /// /// 插入指定列使用 diff --git a/ZR.Repository/Repositories/GendemoRepository.cs b/ZR.Repository/Repositories/GendemoRepository.cs index 97a4d5c..061add0 100644 --- a/ZR.Repository/Repositories/GendemoRepository.cs +++ b/ZR.Repository/Repositories/GendemoRepository.cs @@ -2,6 +2,8 @@ using System; using Infrastructure.Attribute; using ZR.Repository.System; using ZR.Model.Models; +using SqlSugar; +using SqlSugar.IOC; namespace ZR.Repository { @@ -14,12 +16,17 @@ namespace ZR.Repository [AppService(ServiceLifetime = LifeTime.Transient)] public class GendemoRepository : BaseRepository { - public GendemoRepository() : base(configId: "1") + private readonly ISqlSugarClient db; + public GendemoRepository() { + db = DbScoped.SugarScope.GetConnection(1); } #region 业务逻辑代码 - + public void Test() + { + var date = db.GetDate(); + } #endregion } } \ No newline at end of file diff --git a/ZR.Service/Business/GendemoService.cs b/ZR.Service/Business/GendemoService.cs index ecbeea2..7bd56c5 100644 --- a/ZR.Service/Business/GendemoService.cs +++ b/ZR.Service/Business/GendemoService.cs @@ -26,7 +26,12 @@ namespace ZR.Service.Business { _repository = repository; } + #region 业务逻辑代码 + public void Test() + { + _repository.Test(); + } #endregion } } \ No newline at end of file diff --git a/ZR.Service/Business/IBusService/IGendemoService.cs b/ZR.Service/Business/IBusService/IGendemoService.cs index 7e0454c..969afd1 100644 --- a/ZR.Service/Business/IBusService/IGendemoService.cs +++ b/ZR.Service/Business/IBusService/IGendemoService.cs @@ -11,5 +11,6 @@ namespace ZR.Service.Business /// public interface IGendemoService: IBaseService { + void Test(); } }