2017-06-09 42 views
0

在使用Azure函數和DocumentClient進行linq查詢序列化期間,我遇到了一個問題。查詢不使用我的POCO的JsonProperty屬性。Azure函數CosmosDB查詢序列化

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的功能核心工具推出了預編譯的功能。

我的dev environement是:

  • VS 2017年
  • Azure的功能核心工具(最新)
  • 淨4.6.1
  • DocumentDB SDK:1.14.0
  • Newtonsoft :10.0.0

相同的代碼在iisexpress中運行時效果很好。

感謝您的幫助!

回答

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" /> 
所有的包