diff --git a/Tiobon.Core.Api/Controllers/Base/BaseController.cs b/Tiobon.Core.Api/Controllers/Base/BaseController.cs index a2f3064b..18ef87b9 100644 --- a/Tiobon.Core.Api/Controllers/Base/BaseController.cs +++ b/Tiobon.Core.Api/Controllers/Base/BaseController.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.InteropServices.Marshalling; namespace Tiobon.Core.Controllers; diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_QuestionController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_QuestionController.cs index 251c0a47..08027af8 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_QuestionController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_QuestionController.cs @@ -90,9 +90,7 @@ public class Ghre_QuestionController : BaseController Put(long Id, [FromBody] EditGhre_QuestionInput editModel) { - var answers1 = await _ghre_QuestionAnswerServices.Query(d => d.QuestionId == Id); - var answerIds = answers1.Select(x => x.Id).ToList(); - await _ghre_QuestionAnswerServices.DeleteByIds1(answerIds.ToArray()); + await _ghre_QuestionAnswerServices.Delete(x=>x.QuestionId == Id); var answers = editModel.Answers; if (answers.Any()) { diff --git a/Tiobon.Core.IServices/BASE/IBaseServices.cs b/Tiobon.Core.IServices/BASE/IBaseServices.cs index 7068fe90..7ed410d0 100644 --- a/Tiobon.Core.IServices/BASE/IBaseServices.cs +++ b/Tiobon.Core.IServices/BASE/IBaseServices.cs @@ -103,6 +103,13 @@ namespace Tiobon.Core.IServices.BASE Task DeleteByIds(object[] ids); Task DeleteByIds1(long[] ids); + /// + /// 根据表达式,删除实体 + /// + /// + /// + Task Delete(Expression> whereExpression); + Task Update(long Id, TEditDto model); Task Update(Dictionary editModels); Task Update(List model); diff --git a/Tiobon.Core.Repository/BASE/BaseRepository.cs b/Tiobon.Core.Repository/BASE/BaseRepository.cs index 3f02d129..4b13ef64 100644 --- a/Tiobon.Core.Repository/BASE/BaseRepository.cs +++ b/Tiobon.Core.Repository/BASE/BaseRepository.cs @@ -252,6 +252,15 @@ namespace Tiobon.Core.Repository.Base return await _db.Deleteable().In(ids).ExecuteCommandHasChangeAsync(); } + /// + /// 根据表达式,删除实体 + /// + /// 主键ID + /// + public async Task Delete(Expression> whereExpression) + { + return await _db.Deleteable().Where(whereExpression).ExecuteCommandHasChangeAsync(); + } /// /// 查询所有数据 diff --git a/Tiobon.Core.Repository/BASE/IBaseRepository.cs b/Tiobon.Core.Repository/BASE/IBaseRepository.cs index d396c93a..04bf9ef9 100644 --- a/Tiobon.Core.Repository/BASE/IBaseRepository.cs +++ b/Tiobon.Core.Repository/BASE/IBaseRepository.cs @@ -76,6 +76,13 @@ namespace Tiobon.Core.IRepository.Base /// Task DeleteByIds(object[] ids); + /// + /// 根据表达式,删除实体 + /// + /// + /// + Task Delete(Expression> whereExpression); + /// /// 更新model /// diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 490da9d7..40fca34b 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -403,6 +403,8 @@ public class BaseServices : IBaseServ return Mapper.Map(data).ToANew>(); } + #region 新增 + /// /// 写入实体数据 /// @@ -452,6 +454,7 @@ public class BaseServices : IBaseServ }); return await BaseDal.Add(list); } + #endregion /// /// 更新实体数据 @@ -611,6 +614,15 @@ public class BaseServices : IBaseServ return await BaseDal.Update(entities); } + /// + /// 根据表达式,删除实体 + /// + /// 表达式 + /// + public async Task Delete(Expression> whereExpression) + { + return await BaseDal.Delete(whereExpression); + } /// /// 查询所有数据 @@ -891,7 +903,7 @@ public class BaseServices : IBaseServ }; } - + #region 检查表中是否已经存在相同代码的数据 public static void CheckOnly(TEntity entity, long? id = null) { @@ -986,6 +998,7 @@ public class BaseServices : IBaseServ throw; } } + #endregion #endregion } \ No newline at end of file