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