Kat
Kat

Reputation: 2500

Uploading to documentDB is missing inner JSON members of complex objects

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?

Upvotes: 0

Views: 174

Answers (1)

Kat
Kat

Reputation: 2500

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.

Upvotes: 1

Related Questions