Files
QYZH.InteractiveMagazine/QYZH.InteractiveMagazine.Repository/IBaseRepository.cs

103 lines
3.4 KiB
C#
Raw Normal View History


2026-06-01 13:42:40 +08:00
using QYZH.InteractiveMagazine.Models.Dto;
using SqlSugar;
using System.Data;
2026-06-01 13:42:40 +08:00
using System.Linq.Expressions;
namespace QYZH.InteractiveMagazine.Repository
2026-06-01 13:42:40 +08:00
{
public interface IBaseRepository<T> : ISimpleClient<T> where T : class, new()
{
#region add
int Add(T t, bool ignoreNull = true);
int Insert(List<T> t);
int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
IInsertable<T> Insertable(T t);
IUpdateable<T> Updateable();
#endregion add
#region update
int Update(T entity, bool ignoreNullColumns = false, object data = null);
/// <summary>
/// 只更新表达式的值
/// </summary>
/// <param name="entity"></param>
/// <param name="expression"></param>
/// <returns></returns>
int Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false);
int Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
int Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> where);
Task<int> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> where);
#endregion update
/// <summary>
/// 事务 同步
/// </summary>
/// <param name="action"></param>
/// <returns></returns>
Task UseTranAsync(Func<Task> action);
/// <summary>
/// 事务 异步
/// </summary>
/// <param name="action"></param>
/// <returns></returns>
Task<bool> UseTranAsync(Func<Task<bool>> action);
#region delete
IDeleteable<T> Deleteable();
int Delete(object id, string title = "");
int DeleteTable();
bool Truncate();
#endregion delete
#region query
/// <summary>
/// 根据条件查询分页数据
/// </summary>
/// <param name="where"></param>
/// <param name="parm"></param>
/// <returns></returns>
PageListModel<T> GetPages(Expression<Func<T, bool>> where, PageQueryModel parm);
PageListModel<T> GetPages(Expression<Func<T, bool>> where, PageQueryModel parm, Expression<Func<T, object>> order, OrderByType orderEnum = OrderByType.Asc);
PageListModel<T> GetPages(Expression<Func<T, bool>> where, PageQueryModel parm, Expression<Func<T, object>> order, string orderByType);
bool Any(Expression<Func<T, bool>> expression);
ISugarQueryable<T> Queryable();
List<T> GetAll(bool useCache = false, int cacheSecond = 3600);
List<T> SqlQueryToList(string sql, object obj = null);
/// <summary>
/// 根据主值查询单条数据
/// </summary>
/// <param name="pkValue">主键值</param>
/// <returns>泛型实体</returns>
R GetById<R>(object pkValue) where R : class;
Task<R> GetByExpression<R>(Expression<Func<T, bool>> expression) where R : class;
Task<List<T2>> GetListByExpression<T2>(Expression<Func<T, bool>> expression) where T2 : class;
#endregion query
#region Procedure
DataTable UseStoredProcedureToDataTable(string procedureName, List<SugarParameter> parameters);
(DataTable, List<SugarParameter>) UseStoredProcedureToTuple(string procedureName, List<SugarParameter> parameters);
#endregion Procedure
}
2026-06-01 13:42:40 +08:00
}