using Microsoft.EntityFrameworkCore.Query; using System; using System.Collections.Generic; //using System.Data.SqlClient; using Microsoft.Data.SqlClient; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using VOL.Core.Dapper; using VOL.Core.EFDbContext; using VOL.Core.Enums; using VOL.Core.Utilities; using VOL.Entity.SystemModels; namespace VOL.Core.BaseProvider { public interface IRepository where TEntity : BaseEntity { /// /// EF DBContext /// VOLContext DbContext { get; } ISqlDapper DapperContext { get; } /// /// 执行事务。将在执行的方法带入Action /// /// /// WebResponseContent DbContextBeginTransaction(Func action); /// /// 通过条件查询数据 /// /// /// List Find(Expression> where); /// /// /// /// /// 排序字段,数据格式如: /// orderBy = x => new Dictionary() { /// { x.BalconyName,QueryOrderBy.Asc}, /// { x.TranCorpCode1,QueryOrderBy.Desc} /// }; /// /// /// TEntity FindFirst(Expression> predicate, Expression>> orderBy = null); /// /// /// /// where条件 /// 排序字段,数据格式如: /// orderBy = x => new Dictionary() { /// { x.BalconyName,QueryOrderBy.Asc}, /// { x.TranCorpCode1,QueryOrderBy.Desc} /// }; /// /// IQueryable FindAsIQueryable(Expression> predicate, Expression>> orderBy = null); /// /// 通过条件查询数据 /// /// /// 查询条件 /// 返回类型如:Find(x => x.UserName == loginInfo.userName, p => new { uname = p.UserName }); /// List Find(Expression> predicate, Expression> selector); /// /// 根据条件,返回查询的类 /// /// /// /// List Find(Expression> predicate) where TFind : class; Task FindAsyncFirst(Expression> predicate) where TFind : class; Task FindAsyncFirst(Expression> predicate); Task> FindAsync(Expression> predicate) where TFind : class; Task FindFirstAsync(Expression> predicate); Task> FindAsync(Expression> predicate); Task> FindAsync(Expression> predicate, Expression> selector); Task FindFirstAsync(Expression> predicate, Expression> selector); /// /// 多条件查询 /// /// /// 要查询的多个条件的数据源 /// 生成的查询条件 /// List Find(IEnumerable sources, Func>> predicate) where Source : class; /// /// 多条件查询 /// /// /// 要查询的多个条件的数据源 /// 生成的查询条件 /// 自定义返回结果 /// List Find(IEnumerable sources, Func>> predicate, Expression> selector) where Source : class; /// /// 多条件查询 /// /// /// 要查询的多个条件的数据源 /// 生成的查询条件 /// IQueryable FindAsIQueryable(IEnumerable sources, Func>> predicate) where Source : class; Task ExistsAsync(Expression> predicate); bool Exists(Expression> predicate); bool Exists(Expression> predicate) where TExists : class; Task ExistsAsync(Expression> predicate) where TExists : class; IIncludableQueryable Include(Expression> incluedProperty); /// /// /// /// /// /// /// /// /// /// 通过多个字段排序Expression>> /// orderBy = x => new Dictionary() { /// { x.BalconyName,QueryOrderBy.Asc}, /// { x.TranCorpCode1,QueryOrderBy.Desc} /// }; /// 查询返回的对象 /// List QueryByPage(int pageIndex, int pagesize, out int rowcount, Expression> predicate, Expression>> orderBySelector, Expression> selectorResult, bool returnRowCount = true); List QueryByPage(int pageIndex, int pagesize, Expression> predicate, Expression>> orderBy, Expression> selectorResult = null); /// /// /// /// /// /// /// /// /// /// 通过多个字段排序Expression>> /// orderBy = x => new Dictionary() { /// { x.BalconyName,QueryOrderBy.Asc}, /// { x.TranCorpCode1,QueryOrderBy.Desc} /// }; /// List QueryByPage(int pageIndex, int pagesize, out int rowcount, Expression> predicate, Expression>> orderBy, bool returnRowCount = true); IQueryable IQueryablePage(int pageIndex, int pagesize, out int rowcount, Expression> predicate, Expression>> orderBy, bool returnRowCount = true) where TFind : class; IQueryable IQueryablePage(IQueryable queryable, int pageIndex, int pagesize, out int rowcount, Dictionary orderBy, bool returnRowCount = true); /// /// /// /// /// 指定更新字段:x=>new {x.Name,x.Enable} /// 是否保存 /// int Update(TEntity entity, Expression> properties, bool saveChanges = false); /// /// /// /// /// 指定更新字段:x=>new {x.Name,x.Enable} /// 是否保存 /// int Update(TSource entity, Expression> properties, bool saveChanges = false) where TSource : class; int Update(TSource entity, bool saveChanges = false) where TSource : class; int Update(TSource entity, string[] properties, bool saveChanges = false) where TSource : class; int UpdateRange(IEnumerable entities, bool saveChanges = false) where TSource : class; /// /// /// /// /// 指定更新字段:x=>new {x.Name,x.Enable} /// 是否保存 /// int UpdateRange(IEnumerable models, Expression> properties, bool saveChanges = false) where TSource : class; int UpdateRange(IEnumerable entities, string[] properties, bool saveChanges = false) where TSource : class; /// ///修改时同时对明细的添加、删除、修改 /// /// /// 是否修改明细 /// 是否删除明细不存在的数据 /// 主表指定修改字段 /// 明细指定修改字段 /// 是否保存 /// WebResponseContent UpdateRange(TEntity entity, bool updateDetail = false, bool delNotExist = false, Expression> updateMainFields = null, Expression> updateDetailFields = null, bool saveChange = false) where Detail : class; void Delete(TEntity model, bool saveChanges=false); /// /// /// /// /// 是否将子表的数据也删除 /// int Delete(object[] keys, bool delList = false); void Add(TEntity entities, bool SaveChanges = false); void AddRange(IEnumerable entities, bool SaveChanges = false); void AddRange(IEnumerable entities, bool saveChanges = false) where T : class; void Add(TEntity entities, string[] properties, bool saveChanges = false); void AddRange(IEnumerable entities, Expression> properties, bool saveChanges = false) where TSource : class; void AddRange(IEnumerable entities, string[] properties, bool saveChanges = false) where TSource : class; void BulkInsert(IEnumerable entities, bool setOutputIdentity = false); int SaveChanges(); Task SaveChangesAsync(); //执行存储过程 //List RunProc(string sql, params SqlParameter[] pamrs); int ExecuteSqlCommand(string sql, params SqlParameter[] sqlParameters); List FromSql(string sql, params SqlParameter[] sqlParameters); /// /// 执行sql /// 使用方式 FormattableString sql=$"select * from xx where name ={xx} and pwd={xx1} ", /// FromSqlInterpolated内部处理sql注入的问题,直接在{xx}写对应的值即可 /// 注意:sql必须 select * 返回所有TEntity字段, /// /// /// IQueryable FromSqlInterpolated([System.Diagnostics.CodeAnalysis.NotNull] FormattableString sql); /// /// 用于带参数执行sql存储过程 /// /// /// /// Task>> ExecSpAsync(string sql, SqlParameter[] sqlParams); List> ExecSp(string sql, SqlParameter[] sqlParams); /// /// 用于执行直接查询语句 /// /// /// /// Task>> ExecAsync(string sql); List> Exec(string sql, SqlParameter[] sqlParams); Task ExecuteNonQueryAsync(string sql, SqlParameter[] sqlParams); } }