public IQueryable <TResult> Query <TResult>(Domain.QueryOptions options = null) where TResult : class
        {
            if (_databaseName == null)
            {
                throw new DataStoreException("Connect must be called to query CosmosDB");
            }

            return(_client.CreateDocumentQuery <TResult>(UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName), options.ToFeedOptions()));
        }
        public IQueryable <TResult> QueryAsSql <TResult>(string sqlStatement, Domain.QueryOptions queryOptions = null) where TResult : class
        {
            if (string.IsNullOrWhiteSpace(sqlStatement))
            {
                throw new ArgumentException("sqlStatement required to QueryAsSql", nameof(sqlStatement));
            }
            if (_databaseName == null)
            {
                throw new DataStoreException("Connect must be called to query CosmosDB");
            }
            var querySpec = new SqlQuerySpec(sqlStatement);

            return(_client.CreateDocumentQuery <TResult>(UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName), querySpec, queryOptions.ToFeedOptions()));
        }
        public IQueryable <TResult> QueryAsSql <TResult>(string sqlStatement, IEnumerable <DocumentQueryParameter> sqlParameters, Domain.QueryOptions options = null) where TResult : class
        {
            if (sqlParameters == null)
            {
                throw new ArgumentNullException(nameof(sqlParameters));
            }
            if (string.IsNullOrWhiteSpace(sqlStatement))
            {
                throw new ArgumentException("sqlStatement required to QueryAsSql", nameof(sqlStatement));
            }
            if (_databaseName == null)
            {
                throw new DataStoreException("Connect must be called to query CosmosDB");
            }
            var sqlParameterCollection =
                new SqlParameterCollection(sqlParameters.Select(s =>
            {
                var paramName = s.Name;
                if (!paramName.StartsWith("@"))
                {
                    paramName = $"@{paramName}";
                }
                return(new SqlParameter(paramName, s.Value));
            }));
            var querySpec = new SqlQuerySpec(sqlStatement, sqlParameterCollection);

            return(_client.CreateDocumentQuery <TResult>(UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName), querySpec, options.ToFeedOptions()));
        }