增加efcore 官方批量更新
parent
54dea66f5f
commit
39a5e8eade
|
@ -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
|
|||
/// <summary>批量更新,相当于原生sql, 没用EF跟踪方式(所有查询出来,再更新 浪费性能)</summary>
|
||||
Task<bool> BatchUpdateNoTrackingAsync(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TEntity>> updateFactory);
|
||||
|
||||
Task<bool> ExecuteUpdateAsync(Expression<Func<TEntity, bool>> where, Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> setPropertyCalls);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
|
|
@ -232,12 +232,12 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
}
|
||||
|
||||
|
||||
//public static async Task<bool> ExecuteUpdateAsync<T>(this IRaCISDBContext _dbContext, Expression<Func<T, bool>> where, Expression<Func<T, T>> updateFactory, Guid updateUserId) where T : Entity
|
||||
//{
|
||||
public static async Task<bool> ExecuteUpdateAsync<T>(this IRaCISDBContext _dbContext, Expression<Func<T, bool>> where, Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> setPropertyCalls) where T : Entity
|
||||
{
|
||||
|
||||
// return await _dbContext.Set<T>().Where(where).ExecuteUpdateAsync(, );
|
||||
return await _dbContext.Set<T>().Where(where).ExecuteUpdateAsync<T>(setPropertyCalls)>0;
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -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<bool> ExecuteUpdateAsync(Expression<Func<TEntity, bool>> where, Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> setPropertyCalls)
|
||||
{
|
||||
return await _dbContext.ExecuteUpdateAsync(where, setPropertyCalls);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
#region 保存 、忽略 、验证
|
||||
#region 保存 、忽略 、验证
|
||||
public async Task<TEntity> InsertOrUpdateAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
||||
{
|
||||
var entity = _mapper.Map<TEntity>(from);
|
||||
|
|
Loading…
Reference in New Issue