public async Task <QueryResult <CommonQueueProductEndpoint> > QueryByPage(string name, int page, int pageSize) { QueryResult <CommonQueueProductEndpoint> result = new QueryResult <CommonQueueProductEndpoint>(); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _commonQueueConnectionFactory.CreateReadForCommonQueue(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@" select @count= count(*) from [CommonQueueProductEndpoint] where [name] like @name select {0} from [CommonQueueProductEndpoint] where [name] like @name order by [sequence] offset (@pagesize * (@page - 1)) rows fetch next @pagesize rows only;" , StoreHelper.GetCommonQueueProductEndpointSelectFields(string.Empty)) }) { var parameter = new SqlParameter("@page", SqlDbType.Int) { Value = page }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@pagesize", SqlDbType.Int) { Value = pageSize }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@name", SqlDbType.VarChar, 200) { Value = $"{name.ToSqlLike()}%" }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@count", SqlDbType.Int) { Direction = ParameterDirection.Output }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); SqlDataReader reader = null; await using (reader = await commond.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var endpoint = new CommonQueueProductEndpoint(); StoreHelper.SetCommonQueueProductEndpointSelectFields(endpoint, reader, string.Empty); result.Results.Add(endpoint); } await reader.CloseAsync(); result.TotalCount = (int)commond.Parameters["@count"].Value; result.CurrentPage = page; } } }); return(result); }
public async Task <CommonQueueProductEndpoint> QueryByID(Guid id) { CommonQueueProductEndpoint endpoint = null; await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _commonQueueConnectionFactory.CreateReadForCommonQueue(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } await using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"select {0} from [CommonQueueProductEndpoint] where [id]=@id", StoreHelper.GetCommonQueueProductEndpointSelectFields(string.Empty)) }) { var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier) { Value = id }; commond.Parameters.Add(parameter); await commond.PrepareAsync(); SqlDataReader reader = null; await using (reader = await commond.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { endpoint = new CommonQueueProductEndpoint(); StoreHelper.SetCommonQueueProductEndpointSelectFields(endpoint, reader, string.Empty); } await reader.CloseAsync(); } } }); return(endpoint); }