我不确定这是否是模拟器问题,但我有一个非常简单的查询
var collectionUri = UriFactory.CreateDocumentCollectionUri(Constants.CosmosDbName, CollectionName);
var spec = new SqlQuerySpec()
{
QueryText = "SELECT * FROM Users u WHERE u.firstName = @firstname",
Parameters = new SqlParameterCollection
{
new SqlParameter{
Name = "@firstname",
Value = value
}
}
};
var query = client.CreateDocumentQuery<User>(collectionUri, spec);
var users = await query.ToListAsync();
参数化查询不返回结果,即 0 个用户,而下面的相同普通查询返回 1 个匹配 WHERE 条件的用户:
spec.Parameters.Clear();
spec.QueryText = $"SELECT * FROM Users u WHERE u.firstName = '{value}'";
query = client.CreateDocumentQuery<User>(collectionUri, spec);
users = await query.ToListAsync(); // returns 1 user
我是否需要以某种方式显式启用参数化查询,或者我在上面的参数化查询中做错了什么?