using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; namespace Learun.DataBase { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.04 /// 描 述:数据库方法操作接口 /// public interface IDatabase { /// /// 获取连接上下文 /// /// DbConnection getDbConnection(); #region 事务 /// /// 开启事务 /// /// IDatabase BeginTrans(); /// /// 提交 /// /// int Commit(); /// /// 回滚 /// void Rollback(); /// /// 关闭 /// void Close(); #endregion #region 执行 SQL 语句 Task ExecuteAsyncBySql(string strSql); /// /// 执行sql语句 /// /// sql语句 /// int ExecuteBySql(string strSql); /// /// 执行sql语句(带参数) /// /// sql语句 /// 参数 /// int ExecuteBySql(string strSql, object dbParameter); /// /// 执行存储过程 /// /// 存储过程名称 /// int ExecuteByProc(string procName); /// /// 执行存储过程 /// /// 存储过程名称 /// 参数 /// int ExecuteByProc(string procName, object dbParameter); /// /// 执行存储过程 /// /// 存储过程名称 /// T ExecuteByProc(string procName) where T : class; /// /// 执行存储过程 /// /// 存储过程名称 /// 参数 /// T ExecuteByProc(string procName, object dbParameter) where T : class; /// /// 执行存储过程 /// /// 存储过程名称 /// IEnumerable QueryByProc(string procName) where T : class; /// /// 执行存储过程 /// /// 存储过程名称 /// 参数 /// IEnumerable QueryByProc(string procName, object dbParameter) where T : class; #endregion #region 对象实体 添加、修改、删除 /// /// 插入实体数据 /// /// 类型 /// 实体数据 /// int Insert(T entity) where T : class; /// /// 批量插入实体数据 /// /// 类型 /// 实体数据列表 /// int Insert(IEnumerable entities) where T : class; Task InsertAsync(IEnumerable entities) where T : class; /// /// 删除实体数据 /// /// 类型 /// 实体数据(需要主键赋值) /// int Delete(T entity) where T : class; /// /// 批量删除实体数据 /// /// 类型 /// 实体数据列表 /// int Delete(IEnumerable entities) where T : class; /// /// 删除表数据(根据Lambda表达式) /// /// /// /// int Delete(Expression> condition) where T : class,new(); /// /// 更新实体数据 /// /// 类型 /// 实体数据 /// int Update(T entity) where T : class; /// /// 更新实体数据 /// /// 类型 /// 实体数据 /// int UpdateEx(T entity) where T : class; /// /// 批量更新实体数据 /// /// 类型 /// 实体数据列表 /// int Update(IEnumerable entities) where T : class; #endregion #region 对象实体 查询 Task> FindListAsync(string strSql) where T : class; Task> FindListAsync(string strSql, object dbParameter) where T : class; /// /// 查找一个实体根据主键 /// /// 类型 /// 主键 /// T FindEntity(object KeyValue) where T : class; /// /// 查找一个实体(根据表达式) /// /// 类型 /// 表达式 /// T FindEntity(Expression> condition) where T : class,new(); /// /// 查找一个实体(根据sql) /// /// 类型 /// sql语句 /// 参数 /// T FindEntity(string strSql, object dbParameter = null) where T : class,new(); /// /// 获取IQueryable表达式 /// /// 类型 /// IQueryable IQueryable() where T : class,new(); /// /// 获取IQueryable表达式(根据表达式) /// /// 类型 /// 表达式 /// IQueryable IQueryable(Expression> condition) where T : class,new(); /// /// 查询列表(获取表所有数据) /// /// 类型 /// IEnumerable FindList() where T : class,new(); Task> FindListAsync() where T : class, new(); /// /// 查询列表(获取表所有数据) /// /// 类型 /// 排序 /// IEnumerable FindList(Func orderby) where T : class,new(); /// /// 查询列表根据表达式 /// /// 类型 /// 表达式 /// IEnumerable FindList(Expression> condition) where T : class,new(); /// /// 查询列表根据sql语句 /// /// 类型 /// sql语句 /// IEnumerable FindList(string strSql) where T : class; /// /// 查询列表根据sql语句(带参数) /// /// 类型 /// sql语句 /// 参数 /// IEnumerable FindList(string strSql, object dbParameter) where T : class; /// /// 查询列表(分页) /// /// 类型 /// 排序字段 /// 排序类型 /// 每页数据条数 /// 页码 /// 总共数据条数 /// IEnumerable FindList(string orderField, bool isAsc, int pageSize, int pageIndex, out int total) where T : class,new(); /// /// 查询列表(分页)带表达式条件 /// /// 类型 /// 表达式 /// 排序字段 /// 排序类型 /// 每页数据条数 /// 页码 /// 总共数据条数 /// IEnumerable FindList(Expression> condition, string orderField, bool isAsc, int pageSize, int pageIndex, out int total) where T : class,new(); /// /// 查询列表(分页)根据sql语句 /// /// /// sql语句 /// 排序字段 /// 排序类型 /// 每页数据条数 /// 页码 /// 总共数据条数 /// IEnumerable FindList(string strSql, string orderField, bool isAsc, int pageSize, int pageIndex, out int total) where T : class; /// /// 查询列表(分页)根据sql语句 /// /// /// sql语句 /// 参数 /// 排序字段 /// 排序类型 /// 每页数据条数 /// 页码 /// 总共数据条数 /// IEnumerable FindList(string strSql, object dbParameter, string orderField, bool isAsc, int pageSize, int pageIndex, out int total) where T : class; #endregion #region 数据源查询 /// /// 查询数据 /// /// sql语句 /// DataTable FindTable(string strSql); /// /// 查询数据 /// /// sql语句 /// 参数 /// DataTable FindTable(string strSql, object dbParameter); /// /// 查询数据 /// /// sql语句 /// 排序字段 /// 排序类型 /// 每页数据条数 /// 页码 /// 总共数据条数 /// DataTable FindTable(string strSql, string orderField, bool isAsc, int pageSize, int pageIndex, out int total); /// /// 查询数据 /// /// sql语句 /// 参数 /// 排序字段 /// 排序类型 /// 每页数据条数 /// 页码 /// 总共数据条数 /// DataTable FindTable(string strSql, object dbParameter, string orderField, bool isAsc, int pageSize, int pageIndex, out int total); /// /// 获取查询对象 /// /// sql语句 /// object FindObject(string strSql); /// /// 获取查询对象 /// /// sql语句 /// 参数 /// object FindObject(string strSql, object dbParameter); #endregion #region 扩展方法 /// /// 获取数据库表数据 /// /// 反序列化类型 /// IEnumerable GetDBTable() where T : class,new(); /// /// 获取数据库表字段数据 /// /// 反序列化类型 /// 表名 /// IEnumerable GetDBTableFields(string tableName) where T : class,new(); #endregion } }