public DbQueueProc(int index, IQueryProc queryProvider) { ID = Guid.NewGuid(); Index = index; _query = queryProvider; Param = new List <DbParameter>(); }
/// <summary>Execute a Stored Procedure Query that returns no results</summary> /// <param name="args">Query Arguments</param> public async Task Execute(IQueryProc args) { using (var connection = new SqlConnection(options.ConnectionString)) { await connection.OpenAsync().ConfigureAwait(false); using (var cmd = CreateCommand(connection, args.ProcName, args.Parameters)) { await cmd.ExecuteNonQueryAsync().ConfigureAwait(false); } } }
/// <summary>Execute a Stored Procedure Query that returns results</summary> /// <typeparam name="T">Type of the Result</typeparam> /// <param name="args">Query Arguments</param> /// <returns>Set of Results</returns> public async Task <IEnumerable <T> > Execute <T>(IQueryProc <T> args) { args.ResultMapper.ThrowIfNull(nameof(args.ResultMapper)); using (var connection = new SqlConnection(options.ConnectionString)) { await connection.OpenAsync().ConfigureAwait(false); using (var cmd = CreateCommand(connection, args.ProcName, args.Parameters)) { var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false); var list = new List <T>(); while (await reader.ReadAsync().ConfigureAwait(false)) { list.Add(args.ResultMapper(reader.ToDictionary())); } return(list); } } }
public SqlQueryProc(IQueryProc query, IQueueProc queue) { _queue = queue; _query = query; }
/// <summary> /// 创建SQL查询 /// </summary> /// <typeparam name="TEntity">实体类</typeparam> /// <param name="query">数据库持久化</param> /// <param name="queue">当前队列</param> /// <param name="tableName">表名</param> /// <returns></returns> public ISqlQueryProc <TEntity> CreateSqlQuery <TEntity>(IQueryProc query, IQueueProc queue) where TEntity : class, new() { return(new SqlQueryProc <TEntity>(query, queue)); }
/// <summary> /// 创建队列 /// </summary> /// <param name="index">索引</param> /// <param name="query">数据库持久化</param> public IQueueProc CreateQueue(int index, IQueryProc query) { return(new DbQueueProc(index, query)); }