From 39a5e8eade7d938b994bd399b567efe415d2ee01 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 13 Mar 2024 16:13:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0efcore=20=E5=AE=98=E6=96=B9?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs | 3 +++ .../Repository/IRaCISContextExtension.cs | 8 ++++---- IRaCIS.Core.Infra.EFCore/Repository/Repository.cs | 8 +++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index 20a7c1836..de9cad4e7 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using IRaCIS.Core.Domain.Models; using Microsoft.EntityFrameworkCore.ChangeTracking; +using Microsoft.EntityFrameworkCore.Query; namespace IRaCIS.Core.Infra.EFCore { @@ -82,6 +83,8 @@ namespace IRaCIS.Core.Infra.EFCore /// 批量更新,相当于原生sql, 没用EF跟踪方式(所有查询出来,再更新 浪费性能) Task BatchUpdateNoTrackingAsync(Expression> where, Expression> updateFactory); + Task ExecuteUpdateAsync(Expression> where, Expression, SetPropertyCalls>> setPropertyCalls); + #endregion diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs index 1f0074074..25059eb64 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs @@ -232,12 +232,12 @@ namespace IRaCIS.Core.Infra.EFCore } - //public static async Task ExecuteUpdateAsync(this IRaCISDBContext _dbContext, Expression> where, Expression> updateFactory, Guid updateUserId) where T : Entity - //{ + public static async Task ExecuteUpdateAsync(this IRaCISDBContext _dbContext, Expression> where, Expression, SetPropertyCalls>> setPropertyCalls) where T : Entity + { - // return await _dbContext.Set().Where(where).ExecuteUpdateAsync(, ); + return await _dbContext.Set().Where(where).ExecuteUpdateAsync(setPropertyCalls)>0; - //} + } #endregion diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 7901a0a84..32f2520c4 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -14,6 +14,7 @@ using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure.Extention; using Microsoft.Extensions.Localization; +using Microsoft.EntityFrameworkCore.Query; namespace IRaCIS.Core.Infra.EFCore { @@ -369,12 +370,17 @@ namespace IRaCIS.Core.Infra.EFCore } + public async Task ExecuteUpdateAsync(Expression> where, Expression, SetPropertyCalls>> setPropertyCalls) + { + return await _dbContext.ExecuteUpdateAsync(where, setPropertyCalls); + } + #endregion - #region 保存 、忽略 、验证 + #region 保存 、忽略 、验证 public async Task InsertOrUpdateAsync(TFrom from, bool autoSave = false, params EntityVerifyExp[] verify) { var entity = _mapper.Map(from);