1
votes

I have an issue during the serialization of the linq query using Azure function and DocumentClient. The query doesnt use the JsonProperty Attribute of my POCO.

The linq query returns {{"query":"SELECT * FROM root WHERE (root[\"ObjectType\"] = \"Campaign\") "}} instead of {{"query":"SELECT * FROM root WHERE (root[\"objectType\"] = \"Campaign\") "}} The linq query and the 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; }
}

The azure function is a precompiled function launched with azure-functions-core-tools.

My dev environement is:

  • VS 2017
  • azure-functions-core-tools (latest)
  • Net 4.6.1
  • DocumentDB SDK: 1.14.0
  • Newtonsoft: 10.0.0

The same code works well when it run in iisexpress.

Thanks for your help !

1

1 Answers

1
votes

I can't repro that. Having this function

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; }
}

prints {"query":"SELECT * FROM root WHERE (root[\"objectType\"] = \"MyObj\") "} correctly.

Can you try that?

these are all the packages I have in my 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" />