仓储漏提交
parent
eda7ac40bf
commit
326fc3c00f
|
@ -27,8 +27,8 @@ namespace IRaCIS.Application.Services
|
||||||
var c = _dicRepository.Where(t => t.ParentId != null).Select(t => t.MappedValue).First();
|
var c = _dicRepository.Where(t => t.ParentId != null).Select(t => t.MappedValue).First();
|
||||||
CultureInfo culture = CultureInfo.CurrentUICulture;
|
CultureInfo culture = CultureInfo.CurrentUICulture;
|
||||||
|
|
||||||
var dd = _dicRepository.UpdatePartialFields(Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"),
|
//var dd = _dicRepository.UpdatePartialFields(Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"),
|
||||||
u => new Dictionary() { ParentId = null, Code = "test" }, true).Result;
|
// u => new Dictionary() { ParentId = null, Code = "test" }, true);
|
||||||
|
|
||||||
var aaaa = _dicRepository.BatchDeleteAsync(t => t.Id == Guid.Empty).Result;
|
var aaaa = _dicRepository.BatchDeleteAsync(t => t.Id == Guid.Empty).Result;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
|
|
||||||
Task<TEntity> UpdatePartialFields(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp<TEntity>[] verify);
|
Task<TEntity> UpdatePartialFields(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp<TEntity>[] verify);
|
||||||
|
|
||||||
Task<TEntity> UpdatePartialFields(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
Task UpdatePartialFields(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||||
|
|
||||||
|
|
||||||
Task<bool> BatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
|
Task<bool> BatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
|
||||||
|
@ -50,9 +50,13 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
// 不建议使用,使用跟踪,然后save 部分字段更新,此种方式是更新所有字段
|
// 不建议使用,使用跟踪,然后save 部分字段更新,此种方式是更新所有字段
|
||||||
Task<bool> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
|
Task<bool> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
|
||||||
Task<bool> SaveChangesAsync(CancellationToken cancellationToken = default);
|
Task<bool> SaveChangesAsync(CancellationToken cancellationToken = default);
|
||||||
Task<bool> UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default);
|
|
||||||
Task<bool> DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
|
Task<bool> DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
|
||||||
Task<bool> DeleteManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
|
|
||||||
|
//Task<bool> DeleteManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default);
|
||||||
|
//Task<bool> UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -17,7 +16,6 @@ using IRaCIS.Core.Domain.Share;
|
||||||
using IRaCIS.Core.Infrastructure;
|
using IRaCIS.Core.Infrastructure;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Z.EntityFramework.Plus;
|
|
||||||
|
|
||||||
namespace IRaCIS.Core.Infra.EFCore
|
namespace IRaCIS.Core.Infra.EFCore
|
||||||
{
|
{
|
||||||
|
@ -230,7 +228,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
/// <param name="autoSave"></param>
|
/// <param name="autoSave"></param>
|
||||||
/// <param name="verify"></param>
|
/// <param name="verify"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<TEntity> UpdatePartialFields(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
public async Task UpdatePartialFields(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
||||||
{
|
{
|
||||||
await EntityVerifyAsync(false, verify, id);
|
await EntityVerifyAsync(false, verify, id);
|
||||||
|
|
||||||
|
@ -259,8 +257,6 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
|
|
||||||
await SaveChangesAsync(autoSave);
|
await SaveChangesAsync(autoSave);
|
||||||
|
|
||||||
return entityEntry.Entity;
|
|
||||||
|
|
||||||
#region Test
|
#region Test
|
||||||
|
|
||||||
|
|
||||||
|
@ -437,70 +433,9 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
_dbSet.Update(entity);
|
|
||||||
|
|
||||||
if (autoSave)
|
|
||||||
{
|
|
||||||
return await SaveChangesAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<bool> UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
_dbSet.UpdateRange(entities);
|
|
||||||
|
|
||||||
if (autoSave)
|
|
||||||
{
|
|
||||||
return await SaveChangesAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<bool> 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<bool> DeleteManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
_dbSet.RemoveRange(entities);
|
|
||||||
|
|
||||||
if (autoSave)
|
|
||||||
{
|
|
||||||
return await SaveChangesAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<TResult> MaxAsync<TResult>(Expression<Func<TEntity, TResult>> selector)
|
public async Task<TResult> MaxAsync<TResult>(Expression<Func<TEntity, TResult>> selector)
|
||||||
{
|
{
|
||||||
|
@ -533,6 +468,40 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<bool> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
_dbSet.Update(entity);
|
||||||
|
|
||||||
|
if (autoSave)
|
||||||
|
{
|
||||||
|
return await SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<bool> 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<bool> BatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter)
|
public async Task<bool> BatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter)
|
||||||
{
|
{
|
||||||
|
@ -544,8 +513,6 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
Expression<Func<TEntity, TEntity>> updateFactory)
|
Expression<Func<TEntity, TEntity>> updateFactory)
|
||||||
{
|
{
|
||||||
|
|
||||||
//return await _dbSet.IgnoreQueryFilters().Where(where).BatchUpdateAsync(updateFactory) > 0;
|
|
||||||
|
|
||||||
var bindings = ((MemberInitExpression)updateFactory.Body).Bindings.ToList();
|
var bindings = ((MemberInitExpression)updateFactory.Body).Bindings.ToList();
|
||||||
|
|
||||||
if (typeof(IAuditUpdate).IsAssignableFrom(typeof(TEntity)))
|
if (typeof(IAuditUpdate).IsAssignableFrom(typeof(TEntity)))
|
||||||
|
@ -622,6 +589,35 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
// return await _dbSet.IgnoreQueryFilters().Where(where).UpdateFromQueryAsync(updateFactory) > 0;
|
// return await _dbSet.IgnoreQueryFilters().Where(where).UpdateFromQueryAsync(updateFactory) > 0;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
//public async Task<bool> UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||||
|
//{
|
||||||
|
// _dbSet.UpdateRange(entities);
|
||||||
|
|
||||||
|
// if (autoSave)
|
||||||
|
// {
|
||||||
|
// return await SaveChangesAsync(cancellationToken);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//public async Task<bool> DeleteManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||||
|
//{
|
||||||
|
// _dbSet.RemoveRange(entities);
|
||||||
|
|
||||||
|
// if (autoSave)
|
||||||
|
// {
|
||||||
|
// return await SaveChangesAsync(cancellationToken);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue