예제 #1
0
        public override async Task <IEnumerable <TEntity> > GoAsync()
        {
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                ProcedureName = CustomAttributeHandle.DbTableName <TEntity>();
            }
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                throw new MissingProcedureNameException();
            }
            var         procedureName = "[" + SchemaName + "].[" + ProcedureName + "]";
            IDataReader dataReader;

            if (ParameterDefinitions.Any())
            {
                dataReader =
                    await StatementExecutor.ExecuteStoredProcedureAsync(procedureName, ParameterDefinitions.ToArray());
            }
            else
            {
                dataReader = await StatementExecutor.ExecuteStoredProcedureAsync(procedureName);
            }
            var reader = dataReader;

            dataReader = null;
            IEnumerable <TEntity> entities;

            try
            {
                entities = entityMapper.Map <TEntity>(reader);
            }
            finally
            {
                reader?.Dispose();
            }

            return(entities);
        }