Do I need to deserialize the query result from DocumentDb? Do I need to deserialize the query result from DocumentDb? json json

Do I need to deserialize the query result from DocumentDb?


This is what I did and it works. I'd appreciate other answers though if there's a better way.

private async static Task<List<Person>> GetPeopleList(string colSelfLink){   dynamic doc = client.CreateDocumentQuery<Document>(colSelfLink, "SELECT p.PersonId, p.FirstName, p.MiddleName, p.LastName, p.Gender FROM People p").AsEnumerable().ToList();   List<Person> peopleList = new List<Person>();   if (doc != null)   {      Person person;      foreach(var item in doc)      {         person = JsonConvert.DeserializeObject<Person>(item.ToString());         peopleList.Add(person);      }   }   return peopleList;}


Anthony Chu was on the right track with this one. The simple solution is:

private async static Task<List<Person>> GetPeopleList(string colSelfLink){   return client.CreateDocumentQuery<Person>(colSelfLink, "SELECT * FROM People").ToList();}

This will automatically deserialise each returned record and turn it into a People object.


I had this exact same problem, only that my list of objects failing, was nested in another object (document).

public List<MyObject> MyProperty { get; set; }

I am so happy right now that I found the solution:

If you have lists of complex objects in your document, put this on the properties of the complex object:

[JsonProperty(PropertyName = "yourPropertyName")]

This is well known to be needed on the primary object (document), haven't needed them on nested objects though, until they were in a list.