ASP.NET MVC

Adding Class Relationships

The Model classes are related, for example a Customer will take out a Contract. To model these relationships virtual properties need to be added. In this example the Contract is central to the model and you will need to access the Customer, the phone and the Tariff for a particular contract. The example below shows typical virtual properties added to the Contract class and used to establish those relationships

Relationships

In this example customers may wish to display all the phone calls made on their contract for a given time period. To make this easier, the virtual property Messages has been added. The Contract may also need Downloads and Payments to complete all the transactions for a particular mobile phone contract.

  • Contoso University: this is a more complex example of creating a data model with relationships between the classes. See part 1.

MVC Index