示例#1
0
        public override async Task <IPageResult <TKey, TEntity> > SelectPageAsync(IDbConnection conn, int pageNumber, int pageSize, IEnumerable <Expression <Func <TEntity, object> > > selectFields,
                                                                                  WhereClauseResult whereClause = null, string sqlOrderbyClause = null, IDbTransaction tr = null,
                                                                                  CancellationToken cctoken     = new CancellationToken())
        {
            if (conn == null)
            {
                throw new ArgumentNullException(nameof(conn));
            }

            var result = this.ConstructMsSqlSelectPage(pageNumber, pageSize, selectFields, whereClause, sqlOrderbyClause);

            try
            {
                var cmd = base.BuildDapperCmd(result.sql, result.dynParms, tr, cancellationToken: cctoken);

                SqlMapper.GridReader reader = await conn.QueryMultipleAsync(cmd);

                int totalNumberOfRecords = await reader.ReadSingleOrDefaultAsync <int>();

                IEnumerable <TEntity> entities = await reader.ReadAsync <TEntity>();

                return(new PageResult <TKey, TEntity>(pageNumber, pageSize, totalNumberOfRecords).AddItems(entities));
            }
            catch (Exception ex)
            {
                IDictionary <string, object> parameters = new Dictionary <string, object>();
                foreach (var item in result.dynParms.ParameterNames)
                {
                    parameters.Insert(item, result.dynParms.Get <object>(item));
                }

                throw new ExecuteSqlErrorException(result.sql, parameters, ex.Message, ex);
            }
        }
        private static async Task <Voter?> ReadVoterFromMultiQuery(SqlMapper.GridReader multiQuery)
        {
            using (multiQuery)
            {
                var voterEntity = await multiQuery.ReadSingleOrDefaultAsync <VoterEntity>();

                if (voterEntity is null)
                {
                    return(default);
示例#3
0
 public virtual Task <object> ReadSingleOrDefaultAsync() => _gridReader.ReadSingleOrDefaultAsync();