我想将数组作为参数传递给 SqlQuerySpec,以便在为 azure cosmos db 构建查询时能够在 IN 表达式中使用它。我正在尝试做的事情就像我们对常规(字符串、整数等)参数所做的一样:
private SqlQuerySpec BuildQuery(IEnumerable<string> exclTypes)
{
var queryText = "SELECT * FROM root r WHERE r.Type NOT IN (@types)";
var parameters = new SqlParameterCollection{new SqlParameter("@types", exclTypes.ToArray())};
return new SqlQuerySpec()
{QueryText = queryText, Parameters = parameters};
}
Run Code Online (Sandbox Code Playgroud)
但这不会以这种方式工作。我可以通过任何其他方式将数组作为参数传递吗?谢谢。
当我将对象向上插入cosmos db时,我想将对象类型保存为json对象的一部分。我尝试在实例化Cosmos Client实例时传递json序列化器,但是它不起作用。我仍然看不到文档中的对象类型。我正在尝试做的是:
public static readonly JsonSerializerSettings DefaultJsonSerializerSettings =
new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All,
DateFormatString = "o",
DateFormatHandling = DateFormatHandling.IsoDateFormat,
};
var CosmosClient =
new DocumentClient(
new Uri(CosmosConfig.ServiceEndpoint),
CosmosConfig.AuthNKey,
DefaultJsonSerializerSettings,
connectionPolicySettings);
Run Code Online (Sandbox Code Playgroud)
还有其他没有先处理(将对象转换为jObject)的行为的方式吗?谢谢
更新:
我想要达到的目标就像文档中的下一个结构(自动序列化类型):
{
"$type" : "MyNamespace.Foo",
"Id": "1560e1be-bf87-4720-a22e-b7e2c4c37f2e",
"Name" : "Vasia"
}
Run Code Online (Sandbox Code Playgroud)
而不是像这样的当前(无类型):
{
"Id": "1560e1be-bf87-4720-a22e-b7e2c4c37f2e",
"Name" : "Vasia"
}
Run Code Online (Sandbox Code Playgroud)