diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index de9cad4e7..eab56bef7 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -133,6 +133,8 @@ namespace IRaCIS.Core.Infra.EFCore Task> AddRangeAsync(IEnumerable entities, bool autoSave = false); Task SaveChangesAsync(CancellationToken cancellationToken = default); + + Task SaveChangesAndClearAllTrackingAsync(CancellationToken cancellationToken = default); Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 32f2520c4..f9adfda52 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -449,7 +449,12 @@ namespace IRaCIS.Core.Infra.EFCore return await _dbContext.SaveChangesAsync(cancellationToken) > 0; } - + public async Task SaveChangesAndClearAllTrackingAsync(CancellationToken cancellationToken = default) + { + var count = await _dbContext.SaveChangesAsync(cancellationToken); + _dbContext.ChangeTracker.Clear(); + return count > 0; + } #endregion #region 不常用