private static T GetAggregationValue <T>(Expression expression, IReadOnlyCollection <Dictionary <string, object> > dataCollection)
        {
            var methodName = RepositoryExpressionUtilities.GetMethodName(expression);
            var columnName = RepositoryExpressionUtilities.GetAggregationColumnName(methodName);

            return(GetAggregationValue <T>(columnName, dataCollection));
        }
        private static T GetAnyValue <T>(IReadOnlyCollection <Dictionary <string, object> >
                                         dataCollection)
        {
            var columnName = RepositoryExpressionUtilities.GetAnyColumnName();
            var count      = GetAggregationValue <int>(columnName, dataCollection);
            var value      = count > 0;

            if (value is T typedValue)
            {
                return(typedValue);
            }

            return(default(T));
        }
        private T ExecuteScalar <T>(Expression expression)
        {
            var chain          = ExpressionToMetadataConverter.Convert(expression, _elementType);
            var dataCollection = LoadDataCollection(chain);

            if (RepositoryExpressionUtilities.IsAggregationMethodExpression(expression))
            {
                return(GetAggregationValue <T>(expression, dataCollection));
            }
            if (RepositoryExpressionUtilities.IsAnyMethodExpression(expression))
            {
                return(GetAnyValue <T>(dataCollection));
            }
            var models = LoadModelCollection(dataCollection, chain);

            return(ApplyScalarProjector <T>(models.ToList <object>(), chain));
        }