private Search TryExecuteQuery(TranslationResult translationResult, Type entityType)
        {
            QueryFilter queryFilter;
            string      indexName;

            // if we failed to compose a query with table's keys and local secondary indexes
            if (!translationResult.TryGetQueryFilterForTable(this.TableDefinition, out queryFilter, out indexName))
            {
                // then trying to find a suitable Global Secondary Index
                var matchingIndex = this.TableDefinition
                                    .GlobalSecondaryIndexes.Values
                                    .FirstOrDefault
                                    (
                    index => translationResult.TryGetQueryFilterForGlobalSeconaryIndex(index, out queryFilter)
                                    );

                if (matchingIndex == null)
                {
                    return(null);
                }

                indexName = matchingIndex.IndexName;
            }

            var queryConfig = new QueryOperationConfig
            {
                Filter           = queryFilter,
                CollectResults   = false,
                ConsistentRead   = this._consistentRead,
                IndexName        = indexName,
                FilterExpression = translationResult.CustomizationHooks.CustomFilterExpression
            };

            // if a projection is specified - then getting only the required list of fields
            if (translationResult.AttributesToGet != null)
            {
                queryConfig.Select          = SelectValues.SpecificAttributes;
                queryConfig.AttributesToGet = translationResult.AttributesToGet;
            }

            translationResult.CustomizationHooks.ConfigureQueryOperationCallback?.Invoke(queryConfig);

            var searchResult = this.TableDefinition.Query(queryConfig);

            if (string.IsNullOrEmpty(queryConfig.IndexName))
            {
                this.Log("DynamoDb query: {0}", translationResult);
            }
            else
            {
                this.Log("DynamoDb index query: {0}. Index name: {1}", translationResult, queryConfig.IndexName);
            }

            return(searchResult);
        }
        private bool TryExecuteQuery(TranslationResult translationResult, Type entityType, out object resultingReader)
        {
            resultingReader = null;
            QueryFilter queryFilter;
            string      indexName;

            // if we failed to compose a query with table's keys and local secondary indexes
            if (!translationResult.TryGetQueryFilterForTable(this.TableDefinition, out queryFilter, out indexName))
            {
                // then trying to find a suitable Global Secondary Index
                var matchingIndex = this.TableDefinition
                                    .GlobalSecondaryIndexes.Values
                                    .FirstOrDefault
                                    (
                    index => translationResult.TryGetQueryFilterForGlobalSeconaryIndex(index, out queryFilter)
                                    );

                if (matchingIndex == null)
                {
                    return(false);
                }

                indexName = matchingIndex.IndexName;
            }

            var queryConfig = new QueryOperationConfig
            {
                Filter         = queryFilter,
                CollectResults = false,
                ConsistentRead = this._consistentRead,
                IndexName      = indexName
            };

            // if a projection is specified - then getting only the required list of fields
            if (translationResult.AttributesToGet != null)
            {
                queryConfig.Select          = SelectValues.SpecificAttributes;
                queryConfig.AttributesToGet = translationResult.AttributesToGet;
            }

            var searchResult = this.TableDefinition.Query(queryConfig);

            if (string.IsNullOrEmpty(queryConfig.IndexName))
            {
                this.Log("DynamoDb query: " + translationResult);
            }
            else
            {
                this.Log("DynamoDb index query: " + translationResult + ". Index name: " + queryConfig.IndexName);
            }

            resultingReader = this.CreateReader(searchResult, entityType, translationResult.ProjectionFunc);
            return(true);
        }