我在使用 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 启动的预编译函数。
我的开发环境是:
- VS 2017
- azure-functions-core-tools(最新)
- 网络4.6.1
- DocumentDB SDK:1.14.0
- 牛顿软件:10.0.0
相同的代码在 iisexpress 中运行时效果很好。
感谢您的帮助!
最佳答案
我无法重现这一点。有这个功能
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" />
关于linq - Azure 函数 CosmosDB 查询序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44453721/