IsAbandon->IsDeleted
This commit is contained in:
@@ -53,7 +53,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<TrialSiteSurvey>()
|
||||
.HasQueryFilter(t => t.IsAbandon == false);
|
||||
.HasQueryFilter(t => t.IsDeleted == false);
|
||||
|
||||
// 软删除配置
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
|
||||
@@ -37,12 +37,12 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
//Task<T> InsertOrUpdateAsync<T, TFrom>(this DbSet<T> dbset, TFrom from, bool autoSave = false, params EntityVerifyExp<T>[] verify) where T : Entity;
|
||||
|
||||
Task<bool> AnyAsync<T>(Expression<Func<T, bool>> filter) where T : Entity;
|
||||
Task<bool> AnyAsync<T>(Expression<Func<T, bool>> filter, bool ignoreQueryFilters = false) where T : Entity;
|
||||
|
||||
Task<T> FirstOrDefaultAsync<T>(Expression<Func<T, bool>> exp = null) where T : Entity;
|
||||
Task<int> CountAsync<T>(Expression<Func<T, bool>> exp = null) where T : Entity;
|
||||
Task<T> FirstOrDefaultAsync<T>(Expression<Func<T, bool>> exp = null, bool ignoreQueryFilters = false) where T : Entity;
|
||||
Task<int> CountAsync<T>(Expression<Func<T, bool>> exp = null, bool ignoreQueryFilters = false) where T : Entity;
|
||||
|
||||
IQueryable<T> Where<T>(Expression<Func<T, bool>> exp = null, bool isTraking = false) where T : Entity;
|
||||
IQueryable<T> Where<T>(Expression<Func<T, bool>> exp = null, bool isTraking = false, bool ignoreQueryFilters = false) where T : Entity;
|
||||
|
||||
ValueTask<T> FindAsync<T>(Guid id) where T : Entity;
|
||||
|
||||
@@ -167,14 +167,14 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
{
|
||||
if (verifyItem.verifyType == VerifyEnum.OnlyUpdate)
|
||||
{
|
||||
if (await _dbContext.Set<T>().AnyAsync(verifyItem.VerifyExp).ConfigureAwait(false))
|
||||
if (await _dbContext.Set<T>().IgnoreQueryFilters().AnyAsync(verifyItem.VerifyExp).ConfigureAwait(false))
|
||||
{
|
||||
throw new BusinessValidationFailedException(verifyItem.VerifyMsg);
|
||||
}
|
||||
}
|
||||
else if (verifyItem.verifyType == VerifyEnum.Both)
|
||||
{
|
||||
if (await _dbContext.Set<T>().AnyAsync(verifyItem.VerifyExp.And(t => t.Id != entity.Id)).ConfigureAwait(false))
|
||||
if (await _dbContext.Set<T>().IgnoreQueryFilters().AnyAsync(verifyItem.VerifyExp.And(t => t.Id != entity.Id)).ConfigureAwait(false))
|
||||
{
|
||||
throw new BusinessValidationFailedException(verifyItem.VerifyMsg);
|
||||
}
|
||||
@@ -200,9 +200,18 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
{
|
||||
return _dbContext.Entry<T>(t);
|
||||
}
|
||||
public async Task<bool> AnyAsync<T>(Expression<Func<T, bool>> filter) where T : Entity
|
||||
public async Task<bool> AnyAsync<T>(Expression<Func<T, bool>> filter, bool ignoreQueryFilters = false) where T : Entity
|
||||
{
|
||||
return await _dbContext.Set<T>().AnyAsync(filter).ConfigureAwait(false); ;
|
||||
|
||||
var query = _dbContext.Set<T>().AsQueryable();
|
||||
|
||||
if (ignoreQueryFilters)
|
||||
{
|
||||
query = query.IgnoreQueryFilters();
|
||||
}
|
||||
|
||||
return await query.AsNoTracking().AnyAsync(filter).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -217,15 +226,40 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
/// <param name="exp"></param>
|
||||
/// <returns></returns>
|
||||
///
|
||||
public async Task<int> CountAsync<T>(Expression<Func<T, bool>> exp = null) where T : Entity
|
||||
public async Task<int> CountAsync<T>(Expression<Func<T, bool>> exp = null, bool ignoreQueryFilters = false) where T : Entity
|
||||
{
|
||||
if (exp == null) return await _dbContext.Set<T>().CountAsync().ConfigureAwait(false);
|
||||
return await _dbContext.Set<T>().CountAsync(exp).ConfigureAwait(false);
|
||||
var query = _dbContext.Set<T>().AsQueryable();
|
||||
|
||||
if (ignoreQueryFilters)
|
||||
{
|
||||
query = query.IgnoreQueryFilters();
|
||||
}
|
||||
|
||||
if (exp != null)
|
||||
{
|
||||
query = query.Where(exp);
|
||||
}
|
||||
|
||||
return await query.CountAsync().ConfigureAwait(false);
|
||||
|
||||
|
||||
}
|
||||
public async Task<T> FirstOrDefaultAsync<T>(Expression<Func<T, bool>> exp = null) where T : Entity
|
||||
public async Task<T> FirstOrDefaultAsync<T>(Expression<Func<T, bool>> exp = null, bool ignoreQueryFilters = false) where T : Entity
|
||||
{
|
||||
if (exp == null) return await _dbContext.Set<T>().FirstOrDefaultAsync().ConfigureAwait(false);
|
||||
return await _dbContext.Set<T>().FirstOrDefaultAsync(exp).ConfigureAwait(false);
|
||||
|
||||
var query = _dbContext.Set<T>().AsQueryable();
|
||||
|
||||
if (ignoreQueryFilters)
|
||||
{
|
||||
query = query.IgnoreQueryFilters();
|
||||
}
|
||||
|
||||
if (exp != null)
|
||||
{
|
||||
query = query.Where(exp);
|
||||
}
|
||||
|
||||
return await query.FirstOrDefaultAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -235,10 +269,15 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
/// <param name="exp"></param>
|
||||
/// <param name="isTraking"></param>
|
||||
/// <returns></returns>
|
||||
public IQueryable<T> Where<T>(Expression<Func<T, bool>> exp = null, bool isTraking = false) where T : Entity
|
||||
public IQueryable<T> Where<T>(Expression<Func<T, bool>> exp = null, bool isTraking = false, bool ignoreQueryFilters = false) where T : Entity
|
||||
{
|
||||
IQueryable<T> query = _dbContext.Set<T>();
|
||||
|
||||
if (ignoreQueryFilters)
|
||||
{
|
||||
query = query.IgnoreQueryFilters();
|
||||
}
|
||||
|
||||
if (!isTraking)
|
||||
{
|
||||
query = query.AsNoTracking();
|
||||
@@ -356,7 +395,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
{
|
||||
if (whereFilter == null) throw new ArgumentNullException(nameof(whereFilter));
|
||||
|
||||
return await _dbContext.Set<T>().AsNoTracking().Where(whereFilter).UpdateFromQueryAsync(updateFactory).ConfigureAwait(false) > 0;
|
||||
return await _dbContext.Set<T>().AsNoTracking().IgnoreQueryFilters().Where(whereFilter).UpdateFromQueryAsync(updateFactory).ConfigureAwait(false) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
// Z.EntityFramework.Plus.EFCore
|
||||
public async Task<bool> DeleteFromQueryAsync(Expression<Func<TEntity, bool>> deleteFilter)
|
||||
{
|
||||
return await _dbSet.Where(deleteFilter).DeleteFromQueryAsync() > 0;
|
||||
return await _dbSet.IgnoreQueryFilters().Where(deleteFilter).DeleteFromQueryAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateFromQueryAsync(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TEntity>> updateFactory)
|
||||
|
||||
Reference in New Issue
Block a user