From 3ed42384af2167510945bf7b93bfc2464f74f0b0 Mon Sep 17 00:00:00 2001 From: chenchun Date: Thu, 14 Apr 2022 20:44:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E8=A1=8Csql=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/SwaggerDoc.xml | 6 +++++ .../Controllers/TestController.cs | 19 +++++++++++---- .../Yi.Framework.Repository/IRepository.cs | 3 +++ .../Yi.Framework.Repository/Repository.cs | 23 +++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index a8755344..e0877a59 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -57,6 +57,12 @@ + + + 执行sql返回对应Dto + + + 国际化测试 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs index 0cd9394d..7be9570a 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs @@ -36,22 +36,22 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// [HttpGet] // 特点:化繁为简!意框架仓储代理上下文对象,用起来就是爽,但最好按规范来爽! - // 规范:控制器建议不要使用切换仓储方法,控制器严禁使用DB上下文对象,其它怎么爽怎么来! + // 规范:控制器严禁使用切换仓储方法,控制器严禁使用DB上下文对象,其它怎么爽怎么来! public async Task DbTest() { //非常好,使用UserService的特有方法 await _iUserService.DbTest(); - //非常好,依赖注入使用其他Service的特有方法(就tm一张表,自己注入自己) + //非常好,依赖注入使用其他Service的特有方法(就tm一张表,现在自己注入自己) await _iUserService.DbTest(); //很核理,使用仓储的通用方法 await _iUserService._repository.GetListAsync(); - //挺不错,依赖注入其他仓储(就tm一张表,自己注入自己) + //挺不错,依赖注入其他仓储(就tm一张表,现在自己注入自己) await _iUserService._repository.GetListAsync(); - //不建议,但爽了再说,直接切换其他仓储(就tm一张表,自己切换自己) + //严禁操作,直接切换其他仓储(就tm一张表,现在自己切换自己) await _iUserService._repository.ChangeRepository>().GetListAsync(); //恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。 @@ -60,6 +60,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Success().SetData(await _iUserService.DbTest()); } + /// + /// 执行Sql返回对应Dto + /// + /// + [HttpGet] + //简单语句不推荐! + public async Task SqlTest() + { + return Result.Success().SetData(await _iUserService._repository.UseSqlAsync("select * from User")); + } + /// /// 国际化测试 /// diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs index 03494b5c..0883bb9c 100644 --- a/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs +++ b/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs @@ -21,5 +21,8 @@ namespace Yi.Framework.Repository public Task> GetListAsync(QueryCondition pars); public Task DeleteByLogicAsync(List ids); public Task UpdateIgnoreNullAsync(T entity); + public Task> UseSqlAsync(string sql); + public Task UseSqlAsync(string sql); + } } diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs index 58775d25..4b21db78 100644 --- a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs +++ b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs @@ -36,6 +36,29 @@ namespace Yi.Framework.Repository } + /// + /// 执行查询sql返回dto列表 + /// + /// + /// + /// + public async Task> UseSqlAsync(string sql) + { + return await Db.Ado.SqlQueryAsync(sql); + } + + + /// + /// 执行增删改sql返回状态 + /// + /// + /// + public async Task UseSqlAsync(string sql) + { + return await Db.Ado.ExecuteCommandAsync(sql)>0; + } + + /// /// 添加返回实体