0

I'm trying to get multiple documents using a list of numbers. Here's my query

var queryString = "Select * from c Where c.id in (@list)";
var queryParam = new Microsoft.Azure.Documents.SqlParameter("@list", string.Join(",", list.Select(x => $"{x.Id}").ToArray()));
var result = repo.Query(
    new SqlQuerySpec()
        {
            QueryText = queryString,
            Parameters = new Microsoft.Azure.Documents.SqlParameterCollection()
            {
                queryParam
            }
        }
    );

My Query function:

public IQueryable<TClass> Query(SqlQuerySpec sqlQuerySpec = null, bool allowScan = false, int? maxItems = null)
    {
        var feedOptions = new FeedOptions
        {
            EnableScanInQuery = allowScan,
            MaxItemCount = maxItems,
            EnableCrossPartitionQuery = true
        };
        var querySpec = sqlQuerySpec ?? new SqlQuerySpec();
        return sqlQuerySpec != null
            ? Client.CreateDocumentQuery<TClass>(Collection.DocumentsLink, querySpec, feedOptions) 
            : Client.CreateDocumentQuery<TClass>(Collection.DocumentsLink, feedOptions);
    }

It says there was an error: one of the specified inputs is invalid.

What am I doing wrong?

1 Answer 1

1

The id is a string so you would need to wrap each id with single quotes.

This line:

var queryParam = new Microsoft.Azure.Documents.SqlParameter("@list", string.Join(",", list.Select(x => $"{x.Id}").ToArray()));

Should be:

var queryParam = new Microsoft.Azure.Documents.SqlParameter("@list", string.Join(",", list.Select(x => $"'{x.Id}'").ToArray()));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.