From ec5ea3ef9b1826d6f926eedd25a96d413197b7d9 Mon Sep 17 00:00:00 2001 From: izory <791736813@qq.com> Date: Sat, 20 Nov 2021 18:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=93=E5=82=A8=E6=96=B0=E5=A2=9E=E5=B8=B8?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Repository/BaseRepository.cs | 74 +++++++++++++++++--------------- ZR.Repository/IBaseRepository.cs | 14 +++--- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/ZR.Repository/BaseRepository.cs b/ZR.Repository/BaseRepository.cs index 43125f0..3324044 100644 --- a/ZR.Repository/BaseRepository.cs +++ b/ZR.Repository/BaseRepository.cs @@ -3,6 +3,7 @@ using SqlSugar; using SqlSugar.IOC; using System; using System.Collections.Generic; +using System.Data; using System.Linq.Expressions; using ZR.Model; @@ -15,7 +16,7 @@ namespace ZR.Repository public class BaseRepository : IBaseRepository where T : class, new() { public ISqlSugarClient Context; - public BaseRepository(string configId = "0") //: base(dbContext) + public BaseRepository(string configId = "0") { Context = DbScoped.SugarScope.GetConnection(configId);//根据类传入的ConfigId自动选择 } @@ -192,40 +193,45 @@ namespace ZR.Repository } #endregion update - //public DbResult UseTran(Action action) - //{ - // var result = base.Context.Ado.UseTran(() => action()); - // return result; - //} + public DbResult UseTran(Action action) + { + var result = Context.Ado.UseTran(() => action()); + return result; + } - //public DbResult UseTran(SqlSugarClient client, Action action) - //{ - // var result = client.Ado.UseTran(() => action()); - // return result; - //} + public DbResult UseTran(SqlSugarClient client, Action action) + { + var result = client.Ado.UseTran(() => action()); + return result; + } - //public bool UseTran2(Action action) - //{ - // var result = base.Context.Ado.UseTran(() => action()); - // return result.IsSuccess; - //} + public bool UseTran2(Action action) + { + var result = Context.Ado.UseTran(() => action()); + return result.IsSuccess; + } #region delete + /// + /// 删除表达式 + /// + /// + /// public int Delete(Expression> expression) { return Context.Deleteable().Where(expression).ExecuteCommand(); } - //public bool Delete(PkType[] primaryKeyValues) - //{ - // return base.Context.Deleteable().In(primaryKeyValues).ExecuteCommand() > 0; - //} - - //public int Delete(object[] obj) - //{ - // return Context.Deleteable().In(obj).ExecuteCommand(); - //} + /// + /// 批量删除 + /// + /// + /// + public int Delete(object[] obj) + { + return Context.Deleteable().In(obj).ExecuteCommand(); + } public int Delete(object id) { return Context.Deleteable(id).ExecuteCommand(); @@ -370,10 +376,10 @@ namespace ZR.Repository /// /// /// - //public DataTable UseStoredProcedureToDataTable(string procedureName, List parameters) - //{ - // return base.Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters); - //} + public DataTable UseStoredProcedureToDataTable(string procedureName, List parameters) + { + return Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters); + } /// /// 带output返回值 @@ -384,11 +390,11 @@ namespace ZR.Repository /// /// /// - //public (DataTable, List) UseStoredProcedureToTuple(string procedureName, List parameters) - //{ - // var result = (base.Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters), parameters); - // return result; - //} + public (DataTable, List) UseStoredProcedureToTuple(string procedureName, List parameters) + { + var result = (Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters), parameters); + return result; + } //public string QueryableToJson(string select, Expression> expressionWhere) //{ diff --git a/ZR.Repository/IBaseRepository.cs b/ZR.Repository/IBaseRepository.cs index 74e3173..0bfe14f 100644 --- a/ZR.Repository/IBaseRepository.cs +++ b/ZR.Repository/IBaseRepository.cs @@ -81,18 +81,16 @@ namespace ZR.Repository #endregion update - //DbResult UseTran(Action action); + DbResult UseTran(Action action); - //DbResult UseTran(SqlSugarClient client, Action action); + DbResult UseTran(SqlSugarClient client, Action action); - //bool UseTran2(Action action); + bool UseTran2(Action action); #region delete int Delete(Expression> expression); - - //bool Delete(PkType[] primaryKeyValues); - //int Delete(object[] obj); + int Delete(object[] obj); int Delete(object id); bool DeleteTable(); @@ -156,9 +154,9 @@ namespace ZR.Repository #region Procedure - //DataTable UseStoredProcedureToDataTable(string procedureName, List parameters); + DataTable UseStoredProcedureToDataTable(string procedureName, List parameters); - //(DataTable, List) UseStoredProcedureToTuple(string procedureName, List parameters); + (DataTable, List) UseStoredProcedureToTuple(string procedureName, List parameters); #endregion Procedure }