From 326fc3c00fd599cf63994ef1a553ede3ae4be678 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Tue, 19 Apr 2022 09:20:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=93=E5=82=A8=E6=BC=8F=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.Application/TestService.cs | 4 +- .../Repository/ICommandRepository.cs | 10 +- .../Repository/Repository.cs | 132 +++++++++--------- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 3eda5cd9d..6a8ce2864 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -27,8 +27,8 @@ namespace IRaCIS.Application.Services var c = _dicRepository.Where(t => t.ParentId != null).Select(t => t.MappedValue).First(); CultureInfo culture = CultureInfo.CurrentUICulture; - var dd = _dicRepository.UpdatePartialFields(Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"), - u => new Dictionary() { ParentId = null, Code = "test" }, true).Result; + //var dd = _dicRepository.UpdatePartialFields(Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"), + // u => new Dictionary() { ParentId = null, Code = "test" }, true); var aaaa = _dicRepository.BatchDeleteAsync(t => t.Id == Guid.Empty).Result; diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index aea078481..e2abb30d2 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -20,7 +20,7 @@ namespace IRaCIS.Core.Infra.EFCore Task UpdatePartialFields(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp[] verify); - Task UpdatePartialFields(Guid id, Expression> updateFactory, bool autoSave = false, params EntityVerifyExp[] verify); + Task UpdatePartialFields(Guid id, Expression> updateFactory, bool autoSave = false, params EntityVerifyExp[] verify); Task BatchDeleteAsync(Expression> deleteFilter); @@ -50,9 +50,13 @@ namespace IRaCIS.Core.Infra.EFCore // 不建议使用,使用跟踪,然后save 部分字段更新,此种方式是更新所有字段 Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); Task SaveChangesAsync(CancellationToken cancellationToken = default); - Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); - Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); + + + + //Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); + //Task UpdateManyAsync(IEnumerable entities, 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 82e7f41c5..990c2fd8a 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -17,7 +16,6 @@ using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure.Extention; using Microsoft.Data.SqlClient; -using Z.EntityFramework.Plus; namespace IRaCIS.Core.Infra.EFCore { @@ -230,7 +228,7 @@ namespace IRaCIS.Core.Infra.EFCore /// /// /// - public async Task UpdatePartialFields(Guid id, Expression> updateFactory, bool autoSave = false, params EntityVerifyExp[] verify) + public async Task UpdatePartialFields(Guid id, Expression> updateFactory, bool autoSave = false, params EntityVerifyExp[] verify) { await EntityVerifyAsync(false, verify, id); @@ -259,8 +257,6 @@ namespace IRaCIS.Core.Infra.EFCore await SaveChangesAsync(autoSave); - return entityEntry.Entity; - #region Test @@ -437,70 +433,9 @@ namespace IRaCIS.Core.Infra.EFCore } } - public async Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) - { - _dbSet.Update(entity); - - if (autoSave) - { - return await SaveChangesAsync(cancellationToken); - } - else - { - return false; - } - } - public async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) - { - _dbSet.UpdateRange(entities); - - if (autoSave) - { - return await SaveChangesAsync(cancellationToken); - } - else - { - return false; - } - } - - - - - public async Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) - { - _dbSet.Remove(entity); - - //var entry = _dbSet.Attach(entity); - //entry.State = EntityState.Deleted; - - if (autoSave) - { - return await SaveChangesAsync(cancellationToken); - } - else - { - return false; - } - } - - public async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) - { - _dbSet.RemoveRange(entities); - - if (autoSave) - { - return await SaveChangesAsync(cancellationToken); - } - else - { - return false; - } - } - public async Task MaxAsync(Expression> selector) { @@ -533,6 +468,40 @@ namespace IRaCIS.Core.Infra.EFCore } + public async Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + { + _dbSet.Update(entity); + + if (autoSave) + { + return await SaveChangesAsync(cancellationToken); + } + else + { + return false; + } + } + + + + public async Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + { + _dbSet.Remove(entity); + + //var entry = _dbSet.Attach(entity); + //entry.State = EntityState.Deleted; + + if (autoSave) + { + return await SaveChangesAsync(cancellationToken); + } + else + { + return false; + } + } + + public async Task BatchDeleteAsync(Expression> deleteFilter) { @@ -544,8 +513,6 @@ namespace IRaCIS.Core.Infra.EFCore Expression> updateFactory) { - //return await _dbSet.IgnoreQueryFilters().Where(where).BatchUpdateAsync(updateFactory) > 0; - var bindings = ((MemberInitExpression)updateFactory.Body).Bindings.ToList(); if (typeof(IAuditUpdate).IsAssignableFrom(typeof(TEntity))) @@ -622,6 +589,35 @@ namespace IRaCIS.Core.Infra.EFCore // return await _dbSet.IgnoreQueryFilters().Where(where).UpdateFromQueryAsync(updateFactory) > 0; //} + //public async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) + //{ + // _dbSet.UpdateRange(entities); + + // if (autoSave) + // { + // return await SaveChangesAsync(cancellationToken); + // } + // else + // { + // return false; + // } + //} + + + //public async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) + //{ + // _dbSet.RemoveRange(entities); + + // if (autoSave) + // { + // return await SaveChangesAsync(cancellationToken); + // } + // else + // { + // return false; + // } + //} + #endregion