在使用Azure函数和DocumentClient序列化linq查询期间,我遇到了一个问题。查询不使用我的POCO的JsonProperty属性。
linq查询返回{{"query":"SELECT * FROM root WHERE (root[\"ObjectType\"] = \"Campaign\") "}}
而不是{{"query":"SELECT * FROM root WHERE (root[\"objectType\"] = \"Campaign\") "}}
linq查询和POCO
var query = client.CreateDocumentQuery<Obj>(UriFactory.CreateDocumentCollectionUri("db", "col"))
.Where(d => d.ObjectType == "MyObj")
.AsEnumerable();
public class Obj
{
[Newtonsoft.Json.JsonProperty("objectType")]
public string ObjectType { get; set; }
}
azure函数是使用azure-functions-core-tools启动的预编译函数。
我的开发环境是:
相同的代码在iisexpress中运行时效果很好。
感谢您的帮助!
答案 0 :(得分:1)
我不能重复这一点。有这个功能
public static class HttpTriggerCSharp
{
[FunctionName("HttpTriggerCSharp")]
public static async Task<HttpResponseMessage> Run([HttpTrigger()] HttpRequestMessage req, TraceWriter log)
{
var client = new DocumentClient(new Uri("https://example.com"), string.Empty);
var query = client.CreateDocumentQuery<Obj>(UriFactory.CreateDocumentCollectionUri("db", "col"))
.Where(d => d.ObjectType == "MyObj")
.ToString();
log.Info(query);
return req.CreateResponse(HttpStatusCode.OK, "OK");
}
}
public class Obj
{
[Newtonsoft.Json.JsonProperty("objectType")]
public string ObjectType { get; set; }
}
正确打印{"query":"SELECT * FROM root WHERE (root[\"objectType\"] = \"MyObj\") "}
。
你能试试吗?
这些是我csproj
<PackageReference Include="Microsoft.Azure.DocumentDB" Version="1.14.1" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0-alpha5" />