0

I am uploading data to the documentDB using the following code:

   private static async Task UploadEntry(OptimizationData entry)
    {
        try
        {
            string endpointUrl = ConfigurationManager.AppSettings.Get("DocumentDBEndpointURL");
            string authorizationKey = ConfigurationManager.AppSettings.Get("DocumentDBAuthKey");
            string databaseId = ConfigurationManager.AppSettings.Get("DocumentDBDatabaseId");
            string collectionName = ConfigurationManager.AppSettings.Get("CollectionName");

            using (DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
            {
                DocumentCollection documentCollection = client.CreateDocumentCollectionQuery("dbs/" + databaseId).Where(c => c.Id == collectionName).AsEnumerable().FirstOrDefault();

                if (documentCollection != null)
                {
                    await client.CreateDocumentAsync("dbs/" + databaseId + "/colls/" + documentCollection.Id, entry);
                }
            }

        }
        catch
        {
            //Ignored
        }

    }

Now my objects are of these types:

 public class OptimizationData
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public Dictionary<DateTime,OptimizationEntry> Optimization;
}

And Optimization Entry looks like this:

   [DataContract]
   public class OptimizationEntry 
   {
    [DataMember]
    public decimal price{ get; set; }
    public decimal optimalPrice { get; set; }         
    public decimal weight { get; set; }
   }

The problem is, when I look into my document explorer on azure's portal, the inner items of the dictionary are missing. I.e., it has datetime, and the first item (price) but not optimialPrice and Weight

"Optimization": {
"2016-01-27T21:00:00": {
  "price": 179.482711791992
},
"2016-01-27T22:00:00": {
  "price": 196.533660888672
},

 ....

Is there a way I'm supposed to insert the document so that the inner objects are not missed?

1 Answer 1

1

To answer the question for possible future people who need help, the reason they were not showing was that the OptimizationEntry only had "price" as [DataMember] so that it could be serialized, the other two did not. Therefore JSON serialization did not include them in the upload.

Sign up to request clarification or add additional context in comments.

1 Comment

you can also use JSON.NET attributes. [JsonProperty(PropertyName="foo")] if you want to control how the properties are serialized / deserialized/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.