So far, we've focused on pretty simple documents. In practice, however, you're more likely to work with complex JSON structures that mirror your application's object graph. For example, consider the common Customer
class. In this case, you have a Customer
object, which has a collection of Address
objects, as demonstrated in the following C# snippet:
public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public IEnumerable<Address> Addresses { get; set; } } public class Address { public string Street { get; set; } public string City { get; set; } public string Province { get; set; } public string State { get; set; } public string Country { get; set; } public string PostalCode { get; set; } }
In a relational model, this object structure would translate into a one-to-many relationship between a Customers
table and an Addresses
table. By contrast, with document databases, you tend to store related object graphs...