222 lines
10 KiB
C#
222 lines
10 KiB
C#
|
|
|
|||
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Concurrent;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Data.Common;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
using System.Threading;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace APT.Infrastructure.Core
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
public interface IUnitOfWork : IDependInject
|
|||
|
|
{
|
|||
|
|
#region methods
|
|||
|
|
|
|||
|
|
string ConnectionString { get; }
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 对数据库执行给定的 DDL/DML 命令。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sql">命令字符串</param>
|
|||
|
|
/// <param name="parameters">参数</param>
|
|||
|
|
/// <returns>受影响的行数</returns>
|
|||
|
|
int ExecuteSqlCommand(string sql, params object[] parameters);
|
|||
|
|
/// <summary>
|
|||
|
|
/// 对数据库执行给定的 DDL/DML 命令。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="transactionalBehavior">事务行为</param>
|
|||
|
|
/// <param name="sql">命令字符串</param>
|
|||
|
|
/// <param name="parameters">参数</param>
|
|||
|
|
/// <returns>受影响的行数</returns>
|
|||
|
|
int ExecuteSqlCommand(TransactionalBehavior transactionalBehavior, string sql, params object[] parameters);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 对数据库执行给定的 DDL/DML 命令返回reader。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sql">命令字符串</param>
|
|||
|
|
/// <param name="readerAction">reader委托</param>
|
|||
|
|
void ExecuteReader(string sql, ReaderColumn[] readerColumns, Action<DbDataReader> readerAction);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 对数据库执行给定的 DDL/DML 命令返回reader。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sql">命令字符串</param>
|
|||
|
|
/// <param name="parameters">参数</param>
|
|||
|
|
/// <param name="readerAction">reader委托</param>
|
|||
|
|
void ExecuteReader(string sql, ReaderColumn[] readerColumns, DbParameter[] parameters, Action<DbDataReader> readerAction);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 对数据库执行给定的 DDL/DML 命令返回reader。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="commandType">命令类型</param>
|
|||
|
|
/// <param name="sql">命令字符串</param>
|
|||
|
|
/// <param name="parameters">参数</param>
|
|||
|
|
/// <param name="readerAction">reader委托</param>
|
|||
|
|
void ExecuteReader(CommandType commandType, string sql, ReaderColumn[] readerColumns, DbParameter[] parameters, Action<DbDataReader> readerAction);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 对数据库执行给定的 DDL/DML 命令。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="commandType">命令类型</param>
|
|||
|
|
/// <param name="sql">命令字符串</param>
|
|||
|
|
/// <param name="parameters">参数</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
int ExecuteNonQuery(CommandType commandType, string sql, ReaderColumn[] readerColumns, DbParameter[] parameters);
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 创建一个原始 SQL 查询,该查询将返回给定类型的元素。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="elementType">查询所返回对象的类型</param>
|
|||
|
|
/// <param name="sql">SQL 查询字符串</param>
|
|||
|
|
/// <param name="parameters">要应用于 SQL 查询字符串的参数</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
IEnumerable SqlQuery(Type elementType, string sql, ReaderColumn[] readerColumns, params Object[] parameters);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 提交当前单元操作的更改。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns>操作影响的行数</returns>
|
|||
|
|
int SaveChanges();
|
|||
|
|
/// <summary>
|
|||
|
|
/// 执行数据sql语句
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns>执行数据sql语句</returns>
|
|||
|
|
Task<int> ExecuteSqlCommandAsync(TransactionalBehavior transactionalBehavior, string sql, params object[] parameters);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 异步提交当前单元操作的更改。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns>操作影响的行数</returns>
|
|||
|
|
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 开启事务
|
|||
|
|
/// </summary>
|
|||
|
|
void BeginTransaction();
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 提交事务
|
|||
|
|
/// </summary>
|
|||
|
|
void CommitTransaction();
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 回滚事务
|
|||
|
|
/// </summary>
|
|||
|
|
void RollbackTransaction();
|
|||
|
|
|
|||
|
|
T AddEntity<T>(T entity) where T : class;
|
|||
|
|
|
|||
|
|
void AddEntities<T>(IEnumerable<T> entities) where T : class;
|
|||
|
|
|
|||
|
|
public void UpdateEntity<T>(T entity) where T : class;
|
|||
|
|
|
|||
|
|
void UpdateEntities<T>(IEnumerable<T> entities) where T : class;
|
|||
|
|
|
|||
|
|
void UpdateEntities<T>(IEnumerable<T> entities, params string[] updateField) where T : class;
|
|||
|
|
|
|||
|
|
|
|||
|
|
void DeleteEntities<T>(IEnumerable<T> entities) where T : class;
|
|||
|
|
|
|||
|
|
DataBaseType GetDataBaseType();
|
|||
|
|
T GetEntity<T>(Expression<Func<T, bool>> expression, string[] selectField = null, params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
T GetEntity<T>(Expression<Func<T, bool>> expression, string[] selectField = null, bool isTracking = true, params string[] paths) where T : class;
|
|||
|
|
T GetEntity<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders, string[] selectField,
|
|||
|
|
bool isTracking = true, params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
int GetCount<T>(Expression<Func<T, bool>> expression) where T : class;
|
|||
|
|
IEnumerable<T> GetEntities<T>(Expression<Func<T, bool>> expression, string[] selectField = null, params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
IEnumerable<T> GetEntities<T>(Expression<Func<T, bool>> expression, string[] selectField = null, bool isTracking = true, params string[] paths) where T : class;
|
|||
|
|
IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression,
|
|||
|
|
Dictionary<string, DbOrder> orders, string[] selectField = null,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders, string[] selectField = null,
|
|||
|
|
bool isTracking = true, params string[] paths) where T : class;
|
|||
|
|
IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders,
|
|||
|
|
Action<IOrderable<T>> orderBy, string[] selectField,
|
|||
|
|
bool isTracking = true, params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders, string[] selectField,
|
|||
|
|
int pageSize, int startIndex,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders, string[] selectField,
|
|||
|
|
int pageSieze, int startIndex, bool isTracking = true,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders,
|
|||
|
|
int pageSieze, int startIndex, Action<IOrderable<T>> orderBy, bool isTracking = true,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
|
|||
|
|
PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders, string[] selectField,
|
|||
|
|
int pageSize, int startIndex, Action<IOrderable<T>> orderBy, bool isTracking = true,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders,
|
|||
|
|
int pageSize, int startIndex,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders,
|
|||
|
|
int pageSieze, int startIndex, bool isTracking = true,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders,
|
|||
|
|
int pageSieze, int startIndex, Action<IOrderable<T>> orderBy, bool isTracking = true,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
PagedResultDto<T> GetPageEntities<T>(Expression<Func<T, bool>> expression, Dictionary<string, DbOrder> orders, string[] selectField,
|
|||
|
|
int pageSieze, int startIndex, Action<IOrderable<T>> orderBy, bool isTracking = true,
|
|||
|
|
params string[] paths) where T : class;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据表名获取表数据结构
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="tableName"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
EFModelTable GetModelTable(string tableName);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据表名、字段名称获取字段结构
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="tableName"></param>
|
|||
|
|
/// <param name="fieldName"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
EFModelField GetModelField(string tableName, string fieldName);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据表名,导航名称获取外键信息
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="tableName"></param>
|
|||
|
|
/// <param name="navName"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
EFModelForeignKey GetModelForeignKey(string tableName, string navName);
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取所有外键信息
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="tableName"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
List<EFModelForeignKey> GetModelForeignKey(string tableName);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据表名,ID字段名称获取外键信息
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="tableName"></param>
|
|||
|
|
/// <param name="idFieldName"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
EFModelForeignKey GetModelForeignKeyById(string tableName, string idFieldName);
|
|||
|
|
|
|||
|
|
public IEnumerable<TreeNode<T>> GetTreeOrderEntities<T>(Expression<Func<T, bool>> expression, BaseFilter filter,
|
|||
|
|
Expression<Func<T, bool>> orgExpression, out List<T> resultList, bool isTracking = true,
|
|||
|
|
params string[] paths) where T : TreeEntityBase<T>, new();
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|