public int Count(DynamicQuery query, DynamicQuery intermediateQuery)
        {
            query.CustomFunctionMappingStore             = functionMappingStore;
            intermediateQuery.CustomFunctionMappingStore = functionMappingStore;
            var result = adapter.FetchScalar <int?>(intermediateQuery.Select(query.CountRow()));

            if (result.HasValue)
            {
                return(result.Value);
            }

            return(0);
        }