using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using Znyc.Cloudcar.Admin.Commons.Entitys; using Znyc.Cloudcar.Admin.Commons.Pages; namespace Znyc.Cloudcar.Admin.Commons.IDbContext { /// /// 上下文基础接口 /// public interface IDbContextCore : IDisposable { /// /// /// DatabaseFacade GetDatabase(); #region 删除 /// /// 物理删除数据 /// /// /// 主键类型 /// 主键 /// int Delete(TKey key) where T : Entity; /// /// 根据条件删除一个实体,返回影响记录行数 /// /// /// 条件 /// ////int Delete(Expression> @where) where T : class; /// /// 根据条件删除一个实体,返回影响记录行数 /// /// /// 条件 /// //Task DeleteAsync(Expression> @where) where T : class; #endregion 删除 /// /// 执行Sql语句,返回影响记录行数 /// /// /// /// int ExecuteSqlWithNonQuery(string sql, params object[] parameters); /// /// 执行Sql,返回影响记录行数 /// /// /// /// Task ExecuteSqlWithNonQueryAsync(string sql, params object[] parameters); /// /// 批量插入 /// /// /// 数据实体集合 /// 数据库表名称,默认为实体名称 /// void BulkInsert(IList entities, string destinationTableName = null) where T : class; /// /// Sql查询,并返回实体集合 /// /// 查询对象实体 /// 返回/输出实体 /// sql语句 /// SQL参数 /// List SqlQuery(string sql, params object[] parameters) where T : class; /// /// Sql查询,并返回实体集合 /// /// 查询对象实体 /// 返回/输出实体 /// sql语句 /// SQL参数 /// Task> SqlQueryAsync(string sql, params object[] parameters) where T : class where TView : class; /// /// 分页查询,SQL语句查询,返回指定输出对象集合 /// /// 查询对象实体 /// 返回/输出实体 /// sql语句 /// 排序条件 /// 当前页 /// 每页显示数量 /// /// PageResult SqlQueryByPagination(string sql, string[] orderBys, int pageIndex, int pageSize, Action eachAction = null) where T : class where TView : class; /// /// 分页查询,SQL语句查询,返回数据实体集合 /// /// 查询对象实体 /// sql语句 /// 排序条件 /// 当前页 /// 每页显示数量 /// 查询SQL参数 /// PageResult SqlQueryByPagination(string sql, string[] orderBys, int pageIndex, int pageSize, params DbParameter[] parameters) where T : class, new(); /// /// 保存到数据库 /// /// int SaveChanges(); /// /// 保存到数据库 /// /// 更改成功发送到数据库后是否调用AcceptAllChanges() /// int SaveChanges(bool acceptAllChangesOnSuccess); /// /// 保存到数据库 /// /// 是否等待任务完成时要观察 /// Task SaveChangesAsync(CancellationToken cancellationToken = default); /// /// 保存到数据库 /// /// 是否更改成功发送到数据库后是否调用AcceptAllChanges() /// 是否等待任务完成时要观察 /// Task SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default); /// /// 根据sql语句返回DataTable数据 /// /// Sql语句 /// 执行超时时间,默认30毫秒 /// DbParameter[]参数 /// DataTable GetDataTable(string sql, int cmdTimeout = 30, params DbParameter[] parameters); /// /// 根据sql语句返回List集合数据 /// /// Sql语句 /// 执行超时时间,默认30毫秒 /// DbParameter[]参数 /// List GetDataTables(string sql, int cmdTimeout = 30, params DbParameter[] parameters); #region 新增 /// /// 新增实体 /// /// /// /// int Add(T entity) where T : class; /// /// 异步新增 /// /// /// /// Task AddAsync(T entity) where T : class; /// /// 批量新增 /// /// /// /// int AddRange(ICollection entities) where T : class; /// /// 异步批量新增 /// /// /// /// Task AddRangeAsync(ICollection entities) where T : class; #endregion 新增 #region 更新 /// /// 更新保存实体 /// /// /// /// int Edit(T entity) where T : class; /// /// 批量更新保存实体 /// /// /// /// int EditRange(ICollection entities) where T : class; /// /// 更新指定字段的值 /// /// /// 数据实体 /// 指定字段 /// int Update(T model, params string[] updateColumns) where T : class; /// /// 按条件更新, /// /// /// 条件 /// /// //int Update(Expression> @where, Expression> updateFactory) where T : class; /// /// 按条件更新, /// /// /// 条件 /// /// // Task UpdateAsync(Expression> @where, Expression> updateFactory) // where T : class; #endregion 更新 #region 查询 /// /// 根据条件统计数量Count() /// /// /// 查询条件 /// int Count(Expression> where = null) where T : class; /// /// 根据条件异步统计数量Count() /// /// /// 查询条件 /// Task CountAsync(Expression> where = null) where T : class; /// /// 是否存在,存在返回true,不存在返回false /// /// /// 查询条件 /// bool Exist(Expression> where = null) where T : class; /// /// 是否存在,存在返回true,不存在返回false /// /// /// 查询条件 /// Task ExistAsync(Expression> where = null) where T : class; /// /// 根据条件进行查询数据 /// /// /// /// 查询数据 /// IQueryable FilterWithInclude(Func, IQueryable> include, Expression> where) where T : class; /// /// 根据主键查询实体 /// /// /// 主键值 /// T Find(object key) where T : class; /// /// 根据主键查询实体 /// /// /// 主键值 /// T Find(string key) where T : class; /// /// 根据主键查询实体 /// /// /// 主键类型 /// 主键值 /// T Find(TKey key) where T : Entity; /// /// 根据主键查询实体 /// /// /// 主键值 /// Task FindAsync(object key) where T : class; /// /// 根据主键查询实体 /// /// /// 主键类型 /// 主键值 /// Task FindAsync(TKey key) where T : Entity; /// /// 根据条件查询实体,返回实体集合 /// /// /// 查询条件 /// 是否启用模型跟踪,默认为false不跟踪 /// IQueryable Get(Expression> where = null, bool asNoTracking = false) where T : class; /// /// 获取所有实体类型 /// /// List GetAllEntityTypes(); /// /// /// /// DbSet GetDbSet() where T : class; /// /// 根据条件查询一个实体, /// 检验序列中是否包含有元素。引用类型的默认值default(T)为null,表示在序列中没有找到元素。 /// /// /// 查询条件 /// T GetSingleOrDefault(Expression> where = null) where T : class; /// /// 根据条件查询一个实体, /// 检验序列中是否包含有元素。引用类型的默认值default(T)为null,表示在序列中没有找到元素。 /// /// /// 查询条件 /// Task GetSingleOrDefaultAsync(Expression> where = null) where T : class; /// /// 根据条件查询一个实体, /// 异步返回序列的第一个元素,如果序列不包含元素,则返回默认值。 /// 引用类型的默认值default(T)为null,表示在序列中没有找到元素。 /// /// /// 查询条件 /// Task GetFirstOrDefaultAsync(Expression> where = null) where T : class; #endregion 查询 #region 显式编译的查询,提高查询性能 /// /// 根据主键查询返回一个实体,该方法是显式编译的查询 /// /// /// 主键类型 /// 主键值 /// T GetByCompileQuery(TKey id) where T : Entity; /// /// 根据主键查询返回一个实体,该方法是显式编译的查询 /// /// /// 主键类型 /// 主键值 /// Task GetByCompileQueryAsync(TKey id) where T : Entity; /// /// 根据条件查询返回实体集合,该方法是显式编译的查询 /// /// /// 查询条件 /// IList GetByCompileQuery(Expression> filter) where T : class; /// /// 根据条件查询返回实体集合,该方法是显式编译的查询 /// /// /// 查询条件 /// Task> GetByCompileQueryAsync(Expression> filter) where T : class; /// /// 根据条件查询一个实体,该方法是显式编译的查询 /// 检验序列中是否包含有元素。引用类型的默认值default(T)为null,表示在序列中没有找到元素。 /// /// /// 查询条件 /// T FirstOrDefaultByCompileQuery(Expression> filter) where T : class; /// /// 根据条件查询一个实体,该方法是显式编译的查询 /// 检验序列中是否包含有元素。引用类型的默认值default(T)为null,表示在序列中没有找到元素。 /// /// /// 查询条件 /// Task FirstOrDefaultByCompileQueryAsync(Expression> filter) where T : class; /// /// 根据条件查询一个实体,启用模型跟踪,该方法是显式编译的查询 /// 检验序列中是否包含有元素。引用类型的默认值default(T)为null,表示在序列中没有找到元素。 /// /// /// 查询条件 /// T FirstOrDefaultWithTrackingByCompileQuery(Expression> filter) where T : class; /// /// 根据条件查询一个实体,启用模型跟踪,该方法是显式编译的查询 /// 检验序列中是否包含有元素。引用类型的默认值default(T)为null,表示在序列中没有找到元素。 /// /// /// 查询条件 /// Task FirstOrDefaultWithTrackingByCompileQueryAsync(Expression> filter) where T : class; /// /// 统计数量Count(),该方法是显式编译的查询 /// /// /// 查询条件 /// int CountByCompileQuery(Expression> filter) where T : class; /// /// 统计数量Count(),该方法是显式编译的查询 /// /// /// 查询条件 /// Task CountByCompileQueryAsync(Expression> filter) where T : class; #endregion 显式编译的查询,提高查询性能 } }