(Copy Andrew Davis answer from MSDN Forums for DocumentDB for stackoverflow community)
The simplest way would be to inherit the Employee class from Document, and then pour result.Resource for Employee. If you do not want to inherit from the document, you can also define explicit casting between the document and the employee.
Having the Employee class inherited from Document should work if the member names of your Employee class match the names of the corresponding JSON view properties.
Defining your own type conversion gives you more control and might look something like this:
public static explicit operator Employee(Document doc) { Employee emp = new Employee(); emp.Name = doc.GetPropertyValue<string>("employeeName"); emp.Number = doc.GetPropertyValue<int>("employeeNumber"); return emp; }
This would define an explicit cast from Document to Employee. You will need to make sure that the GetPropertyValue strings (and type arguments) match your JSON properties.
Andrew Liu
source share