55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using System.Linq.Expressions;
|
|
using SJZY.Track.Domain;
|
|
using SJZY.Track.Domain.SeedWork;
|
|
using SJZY.Track.Infrastructure.Queries;
|
|
using Volo.Abp;
|
|
|
|
namespace SJZY.Track.Infrastructure.Repositories;
|
|
|
|
/// <summary>
|
|
/// 仓储基类实现
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class BasicRepository<T> : BasicQuery<T>, IBasicRepository<T> where T : class, IAggregateRoot, new()
|
|
{
|
|
public async Task<bool> UpdateAsync(T entity, Expression<Func<T, object>>? ignoreColumns)
|
|
{
|
|
return await Context.Updateable(entity)
|
|
.IgnoreColumnsIF(ignoreColumns != null, ignoreColumns)
|
|
.ExecuteCommandHasChangeAsync();
|
|
}
|
|
|
|
public async Task<bool> UpdateColumnAsync(T entity, Expression<Func<T, object>>? updateColumns)
|
|
{
|
|
return await Context.Updateable(entity)
|
|
.UpdateColumnsIF(updateColumns != null, updateColumns)
|
|
.ExecuteCommandHasChangeAsync();
|
|
}
|
|
|
|
public async Task<bool> UpdateAsync(T entity, bool ignoreAllNullColumns = false, bool ignoreAllDefaultValue = false)
|
|
{
|
|
return await Context.Updateable(entity)
|
|
.IgnoreColumns(ignoreAllNullColumns: ignoreAllNullColumns, ignoreAllDefaultValue: ignoreAllDefaultValue)
|
|
.ExecuteCommandHasChangeAsync();
|
|
}
|
|
|
|
public async Task<bool> UpdateRangeAsync(List<T> entities, Expression<Func<T, object>>? columns = null)
|
|
{
|
|
return await Context.Updateable(entities)
|
|
.UpdateColumnsIF(columns != null, columns)
|
|
.ExecuteCommandHasChangeAsync();
|
|
}
|
|
|
|
// tips: required where
|
|
public async Task<bool> SoftDeleteAsync(Expression<Func<T, bool>> where)
|
|
{
|
|
if (!typeof(T).IsAssignableTo<ISoftDeleteBasicEntity>())
|
|
throw new BusinessException(
|
|
message: $"实体没有实现{nameof(ISoftDeleteBasicEntity)}不能调用{nameof(SoftDeleteAsync)}");
|
|
|
|
return await Context.Updateable<T>()
|
|
.Where(where)
|
|
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), 1)
|
|
.ExecuteCommandHasChangeAsync();
|
|
}
|
|
} |