Converting created document result to POCO

Sam picture Sam · Nov 25, 2014 · Viewed 12.6k times · Source

I have the following code that calls DocumentDB and creates a new Employee document. How do I then convert the result to Employee document again? Basically, I want to capture the created document and convert it to Employee object.

var result = await client.CreateDocumentAsync(collection.SelfLink, employee);

if(result.StatusCode == System.Net.HttpStatusCode.Created)
{
   Employee emp = result.Resource; // How do I convert the result to Employee object here?
}

Answer

Arnab Chakraborty picture Arnab Chakraborty · Dec 4, 2014

You can do a dynamic cast like this:

Employee emp = (dynamic)result.Resource;