EI-Image-Viewer-Api/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs

75 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using IRaCIS.Core.Domain.Models;
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace IRaCIS.Core.Infra.EFCore
{
public interface ICommandRepository<TEntity>: ICommandRepository<TEntity, Guid> where TEntity : Entity
{
Task<TEntity> InsertOrUpdateAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
Task<TEntity> InsertFromDTOAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
Task<TEntity> UpdateFromDTOAsync<TFrom>(TFrom from, bool autoSave = false, bool ignoreDtoNullProperty = true, params EntityVerifyExp<TEntity>[] verify);
Task<TEntity> UpdatePartialFields(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp<TEntity>[] verify);
/// <summary>更新字段,立即提交事务</summary>
Task<bool> UpdatePartialFieldsNow(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, params EntityVerifyExp<TEntity>[] verify);
/// <summary>更新字段,默认不提交事务,一般用于服务里面 和别的操作 一起提交事务</summary>
Task UpdatePartialFields(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
/// <summary>批量删除相当于原生sql 没用EF跟踪方式所有查询出来再删除 浪费性能)</summary>
Task<bool> BatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
/// <summary>批量更新相当于原生sql 没用EF跟踪方式所有查询出来再更新 浪费性能)</summary>
Task<bool> BatchUpdateAsync(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TEntity>> updateFactory);
}
public interface ICommandRepository<TEntity, TKey> where TEntity : class
{
EntityEntry<TEntity> Attach(TEntity entity);
EntityEntry Entry(TEntity t);
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> exp = null, bool ignoreQueryFilters = false);
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> exp,bool ignoreQueryFilters=false);
Task<TResult> MaxAsync<TResult>(Expression<Func<TEntity, TResult>> selector);
Task<int> CountAsync(Expression<Func<TEntity, bool>> whereLambda = null, bool ignoreQueryFilters = false);
ValueTask<TEntity> AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
Task<IEnumerable<TEntity>> AddRangeAsync(IEnumerable<TEntity> entities);
Task<bool> AddRangeAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default);
// 不建议使用使用跟踪然后save 部分字段更新,此种方式是更新所有字段
Task<bool> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
Task<bool> SaveChangesAsync(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> UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default);
}
}