refactor:修复仓储接口和实现中的DeleteAsync方法问题 │
1. 为IBaseRepository接口添加DeleteByIdsAsync方法定义 2. 为所有仓储实现类添加DeleteByIdsAsync方法实现 3. 修复DeviceAppService中deviceId未定义的问题 4. 修复DeviceManagementService中DeleteDeviceByIdAsync方法不存在的问题 5. 修复所有仓储类中DeleteAsync(List<T>)方法实现不正确的问题 6. 修复Email相关仓储类中Deleteable方法参数错误的问题"
This commit is contained in:
@@ -68,19 +68,21 @@ public abstract class BaseRepository<TEntity>
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步删除一个实体。
|
||||
/// 异步批量删除实体。
|
||||
/// </summary>
|
||||
/// <param name="entity">要删除的实体对象。</param>
|
||||
/// <param name="entities">要删除的实体列表。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> DeleteAsync(TEntity entity)
|
||||
public virtual async Task<int> DeleteAsync(List<TEntity> entities)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(entity)
|
||||
var result = await _dbContext.GetInstance().Deleteable(entities)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
_logger.LogInformation($"DeleteAsync Batch {typeof(TEntity).Name}, Count: {entities.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -136,38 +138,9 @@ public abstract class BaseRepository<TEntity>
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据主键 ID 列表批量删除实体。
|
||||
/// </summary>
|
||||
/// <param name="ids">要删除的实体主键 ID 列表。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable<TEntity>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"DeleteByIds {typeof(TEntity).Name}, Count: {ids.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据指定条件获取单个实体。
|
||||
/// </summary>
|
||||
/// <param name="expression">查询条件的 Lambda 表达式。</param>
|
||||
/// <returns>返回满足条件的第一个实体,如果未找到则返回 null。</returns>
|
||||
public virtual async Task<TEntity> GetByConditionAsync(Expression<Func<TEntity, bool>> expression)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var entity = await _dbContext.GetInstance().Queryable<TEntity>()
|
||||
.FirstAsync(expression);
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"GetByCondition {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步判断是否存在满足条件的实体。
|
||||
@@ -264,4 +237,21 @@ public abstract class BaseRepository<TEntity>
|
||||
|
||||
return retrunEntities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据主键 ID 列表批量删除实体。
|
||||
/// </summary>
|
||||
/// <param name="ids">要删除的实体主键 ID 列表。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable<TEntity>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"DeleteByIds {typeof(TEntity).Name}, Count: {ids.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user