我正在尝试使用数字列表获取多个文档。这是我的查询
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
}
}
);
我的查询功能:
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);
}
它说有一个错误:one of the specified inputs is invalid
。
我在做什么错了?
答案 0 :(得分:0)
id
是一个字符串,因此您需要将每个id都用单引号引起来。
此行:
var queryParam = new Microsoft.Azure.Documents.SqlParameter("@list", string.Join(",", list.Select(x => $"{x.Id}").ToArray()));
应该是:
var queryParam = new Microsoft.Azure.Documents.SqlParameter("@list", string.Join(",", list.Select(x => $"'{x.Id}'").ToArray()));