For my management application, i have in my modelfolder a dbml file with entities (ex. person, company, address, contact, …)
With help of mvc i can handle all CRUD operations so far, but only from 1 entity.
Now I want to show in 1 view information of the person entity and also the corresponding information of contact and address entity. The entities are already connected with the correct relations.
How can I do this efficiently ?
You need to create a ViewModel that will be used to hold information from each entity you need within your actual View.
For example, I have a controller called PublicationsController that will build a catalog page within my web application. One ActionResult needs to provide a ViewModel called PublicationsListViewModel to my View.
PublicationsListViewModel:
As you can see, the PublicationsListViewModel is just a container for each Entity that needs to be passed to my View.
My PublicationsController looks like this:
Controller:
And my View looks like this
View: