123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq.Expressions;
- using System.Threading.Tasks;
- namespace Repository
- {
- public interface IRepository
- {
- DbContext GetCurrentDbContext();
- /// <summary>
- /// 添加实体
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="entity"></param>
- /// <returns></returns>
- bool Add<T>(T entity) where T : class;
- /// <summary>
- /// 异步实现
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="entity"></param>
- /// <returns></returns>
- Task<bool> AddAsync<T>(T entity) where T : class;
- /// <summary>
- /// 批量的进行添加实体
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="entity"></param>
- /// <returns></returns>
- bool AddRange<T>(IEnumerable<T> entity) where T : class;
- /// <summary>
- /// 批量的进行添加实体
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="entity"></param>
- /// <returns></returns>
- Task<bool> AddRangeAsync<T>(IEnumerable<T> entity) where T : class;
- /// <summary>
- /// 删除单个实体
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="entity"></param>
- /// <returns></returns>
- bool Delete<T>(T entity) where T : class;
- /// <summary>
- /// 删除所有
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- bool DeleteAll<T>() where T : class;
- /// <summary>
- /// 异步删除所有
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- Task<bool> DeleteAllAsync<T>() where T : class;
- /// <summary>
- /// 根据查询条件进行删除单个实体
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- bool Delete<T>(Expression<Func<T, bool>> whereLambda) where T : class;
- /// <summary>
- /// 根据查询条件进行异步删除单个实体
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- Task<bool> DeleteAsync<T>(Expression<Func<T, bool>> whereLambda) where T : class;
- bool DeleteById<T>(dynamic id) where T : class;
- Task<bool> DeleteByIdAsync<T>(dynamic id) where T : class;
- /// <summary>
- ///单个对象的修改
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="entity">需要修改的对象</param>
- /// <returns></returns>
- bool Update<T>(T entity) where T : class;
- Task<bool> UpdateAsync<T>(T entity) where T : class;
- /// <summary>
- /// 批量修改
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="updateLambda"></param>
- /// <param name="whereLambda">
- /// </param>
- /// <returns></returns>
- bool Update<T>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, T>> updateLambda) where T : class;
- /// <summary>
- /// 异步批量修改
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="updateLambda"></param>
- /// <param name="whereLambda">
- /// </param>
- /// <returns></returns>
- Task<bool> UpdateAsync<T>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, T>> updateLambda) where T : class;
- /// <summary>
- /// 批量的修改
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="entity"></param>
- /// <returns></returns>
- bool Update<T>(List<T> entity) where T : class;
- /// <summary>
- /// 批量统一的进行更新
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="model">需要修改的对象实体</param>
- /// <param name="whereLambda">查询的条件</param>
- /// <param name="modifiedProNames"></param>
- /// <returns></returns>
- bool Update<T>(T model, Expression<Func<T, bool>> whereLambda, params string[] modifiedProNames) where T : class;
- /// <summary>
- /// 根据主键进行查询
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="id"></param>
- /// <returns></returns>
- T FindById<T>(dynamic id) where T : class;
- /// <summary>
- /// 根据主键进行查询异步
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="id"></param>
- /// <returns></returns>
- Task<T> FindByIdAsync<T>(dynamic id) where T : class;
- /// <summary>
- /// 默认查询选择第一条数据,没有那么进行返回NULL
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns>返回bool</returns>
- T GetFirstDefault<T>(Expression<Func<T, bool>> whereLambda = null) where T : class;
- Task<T> GetFirstDefaultAsync<T>(Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- /// 查询所有的数据
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- List<T> GetAll<T>(string orderProperty) where T : class;
- /// <summary>
- /// 查询所有的数据
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- Task<List<T>> GetAllAsync<T>(string orderProperty) where T : class;
- /// <summary>
- /// 含有带条件的查询
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="path">Include Path</param>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- List<T> GetAllQuery<T>(string path,Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- /// 含有带条件的查询
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- List<T> GetAllQuery<T>(Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- /// 异步含有带条件的查询
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- Task<List<T>> GetAllQueryAsync<T>(Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- ///获取查询的数量
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- int GetCount<T>(Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- ///异步获取查询的数量
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- Task<int> GetCountAsync<T>(Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- /// 判断对象是否存在
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- bool GetAny<T>(Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- /// 异步判断对象是否存在
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- Task<bool> GetAnyAsync<T>(Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- /// 根据查询过条件进行分页
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <typeparam name="TKey"></typeparam>
- /// <param name="pageIndex">当前页面</param>
- /// <param name="pageSize">页面的大小</param>
- /// <param name="orderBy">排序的条件</param>
- /// <param name="whereLambda">查询条件</param>
- /// <param name="isOrder">是否正序</param>
- /// <returns></returns>
- List<T> Pagination<T, TKey>(int pageIndex, int pageSize, Expression<Func<T, TKey>> orderBy, Expression<Func<T, bool>> whereLambda = null, bool isOrder = true) where T : class;
- /// <summary>
- /// 异步根据查询过条件进行分页
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <typeparam name="TKey"></typeparam>
- /// <param name="pageIndex">当前页面</param>
- /// <param name="pageSize">页面的大小</param>
- /// <param name="orderBy">排序的条件</param>
- /// <param name="whereLambda">查询条件</param>
- /// <param name="isOrder">是否正序</param>
- /// <returns></returns>
- Task<List<T>> PaginationAsync<T, TKey>(int pageIndex, int pageSize, Expression<Func<T, TKey>> orderBy,
- Expression<Func<T, bool>> whereLambda = null, bool isOrder = true) where T : class;
- /// <summary>
- /// 根据查询条件进行做分页查询
- /// </summary>
- /// <typeparam name="T">查询的对象</typeparam>
- /// <param name="pageIndex">当前的页码</param>
- /// <param name="pageSize">每页的大小</param>
- /// <param name="ordering">排序条件</param>
- /// <param name="whereLambda">查询条件</param>
- /// <returns></returns>
- List<T> Pagination<T>(int pageIndex, int pageSize, string ordering, Expression<Func<T, bool>> whereLambda = null) where T : class;
- /// <summary>
- /// 根据查询条件进行转化
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="whereLambda"></param>
- /// <returns></returns>
- List<T> GetSelect<T>(Expression<Func<T, bool>> whereLambda) where T : class;
- /// <summary>
- /// 执行存储过程或自定义sql语句--返回集合
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="sql"></param>
- /// <param name="parameters"></param>
- /// <param name="cmdType"></param>
- /// <returns></returns>
- List<T> QueryPro<T>(string sql, List<SqlParameter> parameters, CommandType cmdType = CommandType.Text) where T : class;
- /// <summary>
- /// 回滚
- /// </summary>
- /// <typeparam name="T"></typeparam>
- void RollBackChanges<T>() where T : class;
- }
- }
|