The model

As you can see in this simple model, there is a composition relationship (1 to n) between Expense (1) and ExpenseItem (n). Note that the relationship is not aggregation because the expense items make no sense unless the expense referencing them exists.

In a relational database is easy: Foreign keys can be used. In Azure Table Storage you have to find a way of implementing this yourself with the row keys in both tables.

Querying the repository

Now let’s take a look at how we implemented the repository method GetExpenseById: