2017-06-09 39 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" /> 
所有的包